微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何使用此cipherTextBlob将通过Python加密生成的CiphertextBlob转换为Java解密的输入?

如何解决如何使用此cipherTextBlob将通过Python加密生成的CiphertextBlob转换为Java解密的输入?

我有一个使用KMS对称密钥的简单加密程序,并使用boto3在python中进行加密。现在,此加密的输出为密文,例如

以下:

'CiphertextBlob':b'\ x01 \ x02 \ x02 \ x00x \ x86 \ x9c \ xb4 \ x1dc \ xfeo + \ x9d> \ xc8 \ xae \ x9d4 \ x9f \ x80r \ xc3W \ xe2; \ xba \ x9e $ g \ x1eV3i \ x1b \ xbe \ xa6 \ x01 \ xbc- \ x8a \ xeb \ x86 \ xfeC \ r \ xa7 \ xdb \ xdc \ xef + \ xa5 \ xf1 \ x08 \ x00 \ x00 \ x00i x86H \ x86 \ xf7 \ r \ x01 \ x07 \ x06 \ xa0Z0X \ x02 \ x01 \ x000S \ x06 \ t * \ x86H \ x86 \ xf7 \ r \ x01 \ x07 \ x010 \ x1e \ x06 \ t` \ x86H \ x01e \ x03 \ x04 \ x01.0 \ x11 \ x04 \ x0c%\ x90,\ xcf9 \ xf6,\ x9a /; \ xbf \ xd0 \ x02 \ x01 \ x10 \ x80&\ x12〜A \ xa0 \ xf9f \ xcf \ xb7 \ x05“ \ x80 \ xc9 \ xbc \ xd9 \ xb8 \ xda> \ xc4 \ xdd \ x82 \ xde \ xb7b ^ \ xdf \ xec \ x10D \ xbe \ xd6 \ x83:\ xb8 \ x01 \ xf0 \ xa7 \ xfe'

我想将此输出传递给我的Java程序进行解密。但是要在Java中解密,则在Java中,DecryptRequest需要输入SDKBytes类型。

    import json
    import urllib3
    import boto3
    import base64
    
    #def lambda_handler(event,context):
        # Todo implement
    data="Hello World"
    client = boto3.client('kms')
    bytes(data,encoding='utf8'))
    
    response_encrypt = client.encrypt(
          KeyId='f9####8a-####-####-####-####3e50####',Plaintext= bytes(data,encoding='utf8'),EncryptionContext={
            'Test': 'Encryption'
          }
          )
          
    print(response_encrypt)
    
    print("-------------------------------------------")
    
    print(response_encrypt['CiphertextBlob'])
          
    print(response_encrypt)

Java版本

public SdkBytes deCrypt(SdkBytes encryptedJsonString) {
    DecryptRequest decryptRequest = DecryptRequest.builder().ciphertextBlob(encryptedJsonString).build();
    DecryptResponse decryptResponse = this.kmsClient.decrypt(decryptRequest);
    return decryptResponse.plaintext();
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。