@Test public void decodeDefaultAESKey() throws Exception { String decPassword = ENCRYPTOR.decode("9Pav+xl+UyHt02H9ZBytiA==", CipherAlgorithm.AES); assertEquals(PASSWORD_VALUE, decPassword); }
public String decode(final String encoded, final CipherAlgorithm cipherAlgorithm) throws UnsupportedEncodingException, NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException { String decoded = null; if (encoded != null && cipherAlgorithm == CipherAlgorithm.AES) { Cipher cipher = Cipher.getInstance(CipherAlgorithm.AES.getAlgorithm()); cipher.init(Cipher.DECRYPT_MODE, keySpec); decoded = new String(cipher.doFinal(Base64.getDecoder().decode(encoded)), StandardCharsets.UTF_8); } return decoded; }
Encryptor { public String decode(final String encoded, final CipherAlgorithm cipherAlgorithm) throws UnsupportedEncodingException, NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException { String decoded = null; if (encoded != null && cipherAlgorithm == CipherAlgorithm.AES) { Cipher cipher = Cipher.getInstance(CipherAlgorithm.AES.getAlgorithm()); cipher.init(Cipher.DECRYPT_MODE, keySpec); decoded = new String(cipher.doFinal(Base64.getDecoder().decode(encoded)), StandardCharsets.UTF_8); } return decoded; } }
Encryptor { public String decode(final String encoded, final CipherAlgorithm cipherAlgorithm) throws UnsupportedEncodingException, NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException { String decoded = null; if (encoded != null && cipherAlgorithm == CipherAlgorithm.AES) { Cipher cipher = Cipher.getInstance(CipherAlgorithm.AES.getAlgorithm()); cipher.init(Cipher.DECRYPT_MODE, keySpec); decoded = new String(cipher.doFinal(Base64.getDecoder().decode(encoded)), StandardCharsets.UTF_8); } return decoded; } private  Encryptor(final String secretKey); }
Encryptor { public String decode(final String encoded, final CipherAlgorithm cipherAlgorithm) throws UnsupportedEncodingException, NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException { String decoded = null; if (encoded != null && cipherAlgorithm == CipherAlgorithm.AES) { Cipher cipher = Cipher.getInstance(CipherAlgorithm.AES.getAlgorithm()); cipher.init(Cipher.DECRYPT_MODE, keySpec); decoded = new String(cipher.doFinal(Base64.getDecoder().decode(encoded)), StandardCharsets.UTF_8); } return decoded; } private  Encryptor(final String secretKey); static Encryptor getInstance(); static Encryptor getInstance(final String secretKey); String encode(final String value, final CipherAlgorithm cipherAlgorithm); boolean verify(final String value, final CipherAlgorithm cipherAlgorithm, final String encoded); String decode(final String encoded, final CipherAlgorithm cipherAlgorithm); }
Encryptor { public String decode(final String encoded, final CipherAlgorithm cipherAlgorithm) throws UnsupportedEncodingException, NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException { String decoded = null; if (encoded != null && cipherAlgorithm == CipherAlgorithm.AES) { Cipher cipher = Cipher.getInstance(CipherAlgorithm.AES.getAlgorithm()); cipher.init(Cipher.DECRYPT_MODE, keySpec); decoded = new String(cipher.doFinal(Base64.getDecoder().decode(encoded)), StandardCharsets.UTF_8); } return decoded; } private  Encryptor(final String secretKey); static Encryptor getInstance(); static Encryptor getInstance(final String secretKey); String encode(final String value, final CipherAlgorithm cipherAlgorithm); boolean verify(final String value, final CipherAlgorithm cipherAlgorithm, final String encoded); String decode(final String encoded, final CipherAlgorithm cipherAlgorithm);  }