@Test public void testDecryptNull() { assertThat(textEncryptor.decrypt(null)).isEqualTo(""); }
@Override public String decrypt(final String encryptedText) { if (encryptedText == null || encryptedText.isEmpty()) { return EMPTY_STRING; } else { final EncryptedToken token = EncryptedToken.parse(encryptedText); final DecryptRequest decryptRequest = new DecryptRequest() .withCiphertextBlob(token.getCipherBytes()) .withEncryptionContext(token.getEncryptionContext()); final KmsTextEncryptorOptions options = token.getOptions(); final String keyId = Optional.ofNullable(options.getKeyId()).orElse(kmsKeyId); final String algorithm = Optional.ofNullable(options.getEncryptionAlgorithm()).orElse(encryptionAlgorithm); checkAlgorithm(algorithm); if (IS_ALGORITHM_AVAILABLE) { decryptRequest.setEncryptionAlgorithm(algorithm); if (isAsymmetricEncryption(algorithm)) { Assert.hasText(keyId, "kmsKeyId must not be blank. Asymmetric decryption requires the key to be known"); decryptRequest.setKeyId(keyId); } } return extractString(kms.decrypt(decryptRequest).getPlaintext(), options.getOutputMode()); } }
KmsTextEncryptor implements TextEncryptor { @Override public String decrypt(final String encryptedText) { if (encryptedText == null || encryptedText.isEmpty()) { return EMPTY_STRING; } else { final EncryptedToken token = EncryptedToken.parse(encryptedText); final DecryptRequest decryptRequest = new DecryptRequest() .withCiphertextBlob(token.getCipherBytes()) .withEncryptionContext(token.getEncryptionContext()); final KmsTextEncryptorOptions options = token.getOptions(); final String keyId = Optional.ofNullable(options.getKeyId()).orElse(kmsKeyId); final String algorithm = Optional.ofNullable(options.getEncryptionAlgorithm()).orElse(encryptionAlgorithm); checkAlgorithm(algorithm); if (IS_ALGORITHM_AVAILABLE) { decryptRequest.setEncryptionAlgorithm(algorithm); if (isAsymmetricEncryption(algorithm)) { Assert.hasText(keyId, "kmsKeyId must not be blank. Asymmetric decryption requires the key to be known"); decryptRequest.setKeyId(keyId); } } return extractString(kms.decrypt(decryptRequest).getPlaintext(), options.getOutputMode()); } } }
KmsTextEncryptor implements TextEncryptor { @Override public String decrypt(final String encryptedText) { if (encryptedText == null || encryptedText.isEmpty()) { return EMPTY_STRING; } else { final EncryptedToken token = EncryptedToken.parse(encryptedText); final DecryptRequest decryptRequest = new DecryptRequest() .withCiphertextBlob(token.getCipherBytes()) .withEncryptionContext(token.getEncryptionContext()); final KmsTextEncryptorOptions options = token.getOptions(); final String keyId = Optional.ofNullable(options.getKeyId()).orElse(kmsKeyId); final String algorithm = Optional.ofNullable(options.getEncryptionAlgorithm()).orElse(encryptionAlgorithm); checkAlgorithm(algorithm); if (IS_ALGORITHM_AVAILABLE) { decryptRequest.setEncryptionAlgorithm(algorithm); if (isAsymmetricEncryption(algorithm)) { Assert.hasText(keyId, "kmsKeyId must not be blank. Asymmetric decryption requires the key to be known"); decryptRequest.setKeyId(keyId); } } return extractString(kms.decrypt(decryptRequest).getPlaintext(), options.getOutputMode()); } } KmsTextEncryptor(final AWSKMS kms, final String kmsKeyId, final String encryptionAlgorithm); }
KmsTextEncryptor implements TextEncryptor { @Override public String decrypt(final String encryptedText) { if (encryptedText == null || encryptedText.isEmpty()) { return EMPTY_STRING; } else { final EncryptedToken token = EncryptedToken.parse(encryptedText); final DecryptRequest decryptRequest = new DecryptRequest() .withCiphertextBlob(token.getCipherBytes()) .withEncryptionContext(token.getEncryptionContext()); final KmsTextEncryptorOptions options = token.getOptions(); final String keyId = Optional.ofNullable(options.getKeyId()).orElse(kmsKeyId); final String algorithm = Optional.ofNullable(options.getEncryptionAlgorithm()).orElse(encryptionAlgorithm); checkAlgorithm(algorithm); if (IS_ALGORITHM_AVAILABLE) { decryptRequest.setEncryptionAlgorithm(algorithm); if (isAsymmetricEncryption(algorithm)) { Assert.hasText(keyId, "kmsKeyId must not be blank. Asymmetric decryption requires the key to be known"); decryptRequest.setKeyId(keyId); } } return extractString(kms.decrypt(decryptRequest).getPlaintext(), options.getOutputMode()); } } 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 decrypt(final String encryptedText) { if (encryptedText == null || encryptedText.isEmpty()) { return EMPTY_STRING; } else { final EncryptedToken token = EncryptedToken.parse(encryptedText); final DecryptRequest decryptRequest = new DecryptRequest() .withCiphertextBlob(token.getCipherBytes()) .withEncryptionContext(token.getEncryptionContext()); final KmsTextEncryptorOptions options = token.getOptions(); final String keyId = Optional.ofNullable(options.getKeyId()).orElse(kmsKeyId); final String algorithm = Optional.ofNullable(options.getEncryptionAlgorithm()).orElse(encryptionAlgorithm); checkAlgorithm(algorithm); if (IS_ALGORITHM_AVAILABLE) { decryptRequest.setEncryptionAlgorithm(algorithm); if (isAsymmetricEncryption(algorithm)) { Assert.hasText(keyId, "kmsKeyId must not be blank. Asymmetric decryption requires the key to be known"); decryptRequest.setKeyId(keyId); } } return extractString(kms.decrypt(decryptRequest).getPlaintext(), options.getOutputMode()); } } KmsTextEncryptor(final AWSKMS kms, final String kmsKeyId, final String encryptionAlgorithm); @Override String encrypt(final String text); @Override String decrypt(final String encryptedText);  }