When trying decrtypt the code the AWS Encryption SDK throws below exception.
AWS.EncryptionSDK.AwsEncryptionSdkException: Unsupported Version value.
Below is the code used to decrypt.
string keyArn = "**************";
var materialProviders =
AwsCryptographicMaterialProvidersFactory.CreateDefaultAwsCryptographicMaterialProviders();
// Configure the commitment policy on the AWS Encryption SDK instance
var config = new AwsEncryptionSdkConfig
{
CommitmentPolicy = CommitmentPolicy.REQUIRE_ENCRYPT_ALLOW_DECRYPT
};
var encryptionSdk = AwsEncryptionSdkFactory.CreateAwsEncryptionSdk(config);
// Instantiate the keyring input object
var kmsKeyringInput = new CreateAwsKmsKeyringInput
{
KmsClient = new AmazonKeyManagementServiceClient("******", "**********"),
KmsKeyId = keyArn
};
var keyring = materialProviders.CreateAwsKmsKeyring(kmsKeyringInput);
using (var stream = GenerateStreamFromString(smsSenderEvent.Request.Code))
{
var decryptInput = new DecryptInput
{
Ciphertext = stream,
Keyring = keyring
};
logger?.LogInformation("UserManagementService: SendInvitationSms Before Decrypt");
var decryptOutput = encryptionSdk.Decrypt(decryptInput);
logger?.LogInformation("UserManagementService: SendInvitationSms After Decrypt");
}
Below is used to convert code to memory stream.
public static MemoryStream GenerateStreamFromString(string s)
{
var stream = new MemoryStream();
var writer = new StreamWriter(stream);
writer.Write(s);
writer.Flush();
stream.Position = 0;
return stream;
}
Appreciate any help on this issue.