@Test public void testEncryptNull() { assertThat(textEncryptor.encrypt(null)).isEqualTo(""); }
@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); } }
KmsTextEncryptor implements TextEncryptor { @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); } } }
KmsTextEncryptor implements TextEncryptor { @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); } } KmsTextEncryptor(final AWSKMS kms, final String kmsKeyId, final String encryptionAlgorithm); }
KmsTextEncryptor implements TextEncryptor { @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); } } KmsTextEncryptor(final AWSKMS kms, final String kmsKeyId, final String encryptionAlgorithm); @Override String encrypt(final String text); @Override String decrypt(final String encryptedText); }
KmsTextEncryptor implements TextEncryptor { @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); } } KmsTextEncryptor(final AWSKMS kms, final String kmsKeyId, final String encryptionAlgorithm); @Override String encrypt(final String text); @Override String decrypt(final String encryptedText);  }