use of software.amazon.awssdk.services.kms.model.DecryptRequest in project aws-doc-sdk-examples by awsdocs.
the class KMSEncryptionExample method decryptData.
// Decrypt the data passed as a byte array
private static byte[] decryptData(byte[] data, String keyId) {
try {
KmsClient kmsClient = getKMSClient();
SdkBytes encryptedData = SdkBytes.fromByteArray(data);
DecryptRequest decryptRequest = DecryptRequest.builder().ciphertextBlob(encryptedData).keyId(keyId).build();
DecryptResponse decryptResponse = kmsClient.decrypt(decryptRequest);
SdkBytes plainText = decryptResponse.plaintext();
return plainText.asByteArray();
} catch (KmsException e) {
System.err.println(e.getMessage());
System.exit(1);
}
return null;
}
use of software.amazon.awssdk.services.kms.model.DecryptRequest in project aws-doc-sdk-examples by awsdocs.
the class EncryptDataKey method decryptData.
// snippet-end:[kms.java2_encrypt_data.main]
// snippet-start:[kms.java2_decrypt_data.main]
public static void decryptData(KmsClient kmsClient, SdkBytes encryptedData, String keyId) {
try {
DecryptRequest decryptRequest = DecryptRequest.builder().ciphertextBlob(encryptedData).keyId(keyId).build();
DecryptResponse decryptResponse = kmsClient.decrypt(decryptRequest);
decryptResponse.plaintext();
} catch (KmsException e) {
System.err.println(e.getMessage());
System.exit(1);
}
}
Aggregations