Java Code Examples for com.amazonaws.services.kms.model.EncryptRequest#setEncryptionAlgorithm()
The following examples show how to use
com.amazonaws.services.kms.model.EncryptRequest#setEncryptionAlgorithm() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: KmsTextEncryptor.java From spring-cloud-config-aws-kms with Apache License 2.0 | 6 votes |
@Override public String encrypt(final String text) { Assert.hasText(kmsKeyId, "kmsKeyId must not be blank"); if (text == null || text.isEmpty()) { return EMPTY_STRING; } else { final EncryptRequest encryptRequest = new EncryptRequest() .withKeyId(kmsKeyId) .withPlaintext(ByteBuffer.wrap(text.getBytes())); checkAlgorithm(encryptionAlgorithm); if (IS_ALGORITHM_AVAILABLE) { encryptRequest.setEncryptionAlgorithm(encryptionAlgorithm); } final ByteBuffer encryptedBytes = kms.encrypt(encryptRequest).getCiphertextBlob(); return extractString(encryptedBytes, BASE64); } }
Example 2
Source File: KmsTextEncryptorTest.java From spring-cloud-config-aws-kms with Apache License 2.0 | 6 votes |
@Before public void setUp() { mockKms = mock(AWSKMS.class); textEncryptor = new KmsTextEncryptor(mockKms, KMS_KEY_ID, SYMMETRIC_DEFAULT.toString()); expectedEncryptRequest = new EncryptRequest(); expectedEncryptRequest.setKeyId(KMS_KEY_ID); expectedEncryptRequest.setPlaintext(wrap(PLAINTEXT.getBytes())); expectedEncryptRequest.setEncryptionAlgorithm(SYMMETRIC_DEFAULT.toString()); encryptResult = new EncryptResult(); encryptResult.setCiphertextBlob(wrap(CIPHER_TEXT.getBytes())); when(mockKms.encrypt(any(EncryptRequest.class))).thenReturn(encryptResult); expectedDecryptRequest = new DecryptRequest(); expectedDecryptRequest.setCiphertextBlob(wrap(CIPHER_TEXT.getBytes())); expectedDecryptRequest.setEncryptionAlgorithm(SYMMETRIC_DEFAULT.toString()); decryptResult = new DecryptResult(); decryptResult.setPlaintext(wrap(PLAINTEXT.getBytes())); when(mockKms.decrypt(any(DecryptRequest.class))).thenReturn(decryptResult); }