Coder Social home page Coder Social logo

kms#decrypt throws 'utf8' codec error about boto3 HOT 7 CLOSED

boto avatar boto commented on August 15, 2024
kms#decrypt throws 'utf8' codec error

from boto3.

Comments (7)

jstnblau avatar jstnblau commented on August 15, 2024 2

The workaround worked for me, but I had to base64 encode the Plaintext as well.

encrypted=kms.encrypt(KeyId='', Plaintext='Test')
decrypted=kms.decrypt(CiphertextBlob=base64.b64encode(encrypted['CiphertextBlob']).decode('utf-8'))
base64.b64encode(decrypted['Plaintext']).decode('utf-8')

from boto3.

danielgtaylor avatar danielgtaylor commented on August 15, 2024

@bilalaslam this appears to be a bug in Botocore where the CiphertextBlob should automatically be base64-encoded. For example, this appears to work for me:

import base64

kms.decrypt(CiphertextBlob=base64.b64encode(result['CiphertextBlob']).decode('utf-8'))

You can use that as a workaround for now, but once we make the underlying fix you'll need to remove the manual base64-encoding.

from boto3.

spgta avatar spgta commented on August 15, 2024

I can confirm the bug on my end too.

from boto3.

danielgtaylor avatar danielgtaylor commented on August 15, 2024

@spgta does the workaround work for you? This should get fixed in Botocore soon.

from boto3.

spgta avatar spgta commented on August 15, 2024

@danielgtaylor

This works for me:
encrypt:

    kms = boto3.client("kms")   
    e = kms.encrypt(KeyId=self.keyid,EncryptionContext={""},Plaintext=encoded_file)
    self.objectBody = base64.b64encode(e['CiphertextBlob']).decode("utf-8")

decrypt:

kms = boto3.client("kms")
decrypted_file = kms.decrypt(CiphertextBlob=enc_string,EncryptionContext="")

from boto3.

danielgtaylor avatar danielgtaylor commented on August 15, 2024

@spgta, @jstnblau, @bilalaslam this should be fixed upstream with boto/botocore#397, which was just merged. It'll go out with the next release.

from boto3.

danielgtaylor avatar danielgtaylor commented on August 15, 2024

Released in version 0.0.5

from boto3.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.