Why am I receiving AWS.EncryptionSDK.AwsEncryptionSdkException "Failed to build header body". when trying to encrypt a string

0

Using the sample code below I receive the error on the line indicated in the comment below. I am able to encrypt and decrypt using the same key and account via aws kms cli.

public  MemoryStream EncryptMessageWithKMSKey(MemoryStream plaintext, string kmsKeyArn)
{
    var materialProviders =
        AwsCryptographicMaterialProvidersFactory.CreateDefaultAwsCryptographicMaterialProviders();
    var encryptionSdk = AwsEncryptionSdkFactory.CreateDefaultAwsEncryptionSdk();
    var createKeyringInput = new CreateAwsKmsMrkMultiKeyringInput()
    {
        Generator = kmsKeyArn
    };
    var encryptionContext = new Dictionary<string, string>()
    {
        {"purpose", "test"}
    };
    var encryptKeyring = materialProviders.CreateAwsKmsMrkMultiKeyring(createKeyringInput);
    var encryptInput = new EncryptInput
    {
        Plaintext = plaintext,
        Keyring = encryptKeyring,
        EncryptionContext = encryptionContext
    };
    var encryptOutput = encryptionSdk.Encrypt(encryptInput);  // error here !!!!!!!!!!!!!!!!!!!!
    var ciphertext = encryptOutput.Ciphertext;
    return ciphertext;
}
  • Using AWS.EncryptionSDK 3.1.0 (latest at time of writing) AWSSDK.KeyManagamentService 3.7.200.18

  • The last log entry before it fails is AmazonKeyManagementServiceClient ... Received Response (truncated to 1024 bytes)

1개 답변
0

I am able to encrypt and decrypt using the same key and account via aws kms cli.

Are you referring to KMS CLI encrypt and decrypt? If so, you cannot use AWS Encryption SDK, which is a client-side encryption library, to decrypt a ciphertext that's encrypted by KMS directly. You have to use AWS SDK to call the KMS API with your payload. Unfortunately there isn't an example for encrypt and decrypt but think you should be able to piece it together (here's Python example if it helps).

Also this video: https://www.youtube.com/watch?v=YfoCNCuVSlI

AWS
답변함 9달 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠