### Question:
AthenaUDFHandler extends UserDefinedFunctionHandler { public String decrypt(String ciphertext, String secretName) { String secretString = cachableSecretsManager.getSecret(secretName); byte[] plaintextKey = Base64.getDecoder().decode(secretString); try { Cipher cipher = getCipher(Cipher.DECRYPT_MODE, plaintextKey); byte[] encryptedContent = Base64.getDecoder().decode(ciphertext.getBytes()); byte[] plainTextBytes = cipher.doFinal(encryptedContent); return new String(plainTextBytes); } catch (IllegalBlockSizeException | BadPaddingException e) { throw new RuntimeException(e); } } AthenaUDFHandler(); @VisibleForTesting  AthenaUDFHandler(CachableSecretsManager cachableSecretsManager); String compress(String input); String decompress(String input); String decrypt(String ciphertext, String secretName); String encrypt(String plaintext, String secretName);  }### Answer:
@Test public void testKmsDecryption() throws Exception { SecretKeySpec skeySpec = new SecretKeySpec(decoder.decode(PLAINTEXT_DATA_KEY), "AES"); Cipher cipher = Cipher.getInstance("AES"); cipher.init(Cipher.ENCRYPT_MODE, skeySpec); String expected = "abcdef"; String encryptedString = new String(encoder.encode(cipher.doFinal(expected.getBytes()))); String result = athenaUDFHandler.decrypt(encryptedString, DUMMY_SECRET_NAME); assertEquals(expected, result); }
@Ignore("Enabled as needed to do end-to-end test") @Test public void testKmsDecryptionEndToEnd() throws Exception { String secretName = "<fill-in-your-secret-name>"; String secretValue = "<fill-in-secret-value>"; this.athenaUDFHandler = new AthenaUDFHandler(); SecretKeySpec skeySpec = new SecretKeySpec(decoder.decode(secretValue), "AES"); Cipher cipher = Cipher.getInstance("AES"); cipher.init(Cipher.ENCRYPT_MODE, skeySpec); String expected = "abcdef"; String encryptedString = new String(encoder.encode(cipher.doFinal(expected.getBytes()))); String result = athenaUDFHandler.decrypt(encryptedString, secretName); assertEquals(expected, result); }
@Ignore("Enabled as needed to do end-to-end test") @Test public void testKmsEncryptionEndToEnd() throws Exception { String secretName = "<fill-in-your-secret-name>"; String secretValue = "<fill-in-secret-value>"; this.athenaUDFHandler = new AthenaUDFHandler(); SecretKeySpec skeySpec = new SecretKeySpec(decoder.decode(secretValue), "AES"); Cipher cipher = Cipher.getInstance("AES"); cipher.init(Cipher.ENCRYPT_MODE, skeySpec); String expected = "abcdef"; String encryptedString = new String(encoder.encode(cipher.doFinal(expected.getBytes()))); String result = athenaUDFHandler.decrypt(encryptedString, secretName); assertEquals(expected, result); }