如何使用此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 (将#修改为@)