Olá pessoal.
Estou tendo problema em decriptar senhas com mais de 15 caracteres usando as classes do pacote javax.cript.
Quando a senha é maior que 15 caracteres é lançada a exceção:
Input length must be multiple of 16 when decrypting with padded cipher
private static final String METODO_ENCRIPTACAO_AES = "AES";
private static final byte[] KEY = "fsfdsfdsfdsff".getBytes();
public static String encryptAES(String passText)
throws NoSuchAlgorithmException, NoSuchPaddingException,
InvalidKeyException, IllegalBlockSizeException,
BadPaddingException, UnsupportedEncodingException {
byte[] passByte = passText.getBytes("ISO-8859-1");
Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
cipher.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(Crypt.KEY,
Crypt.METODO_ENCRIPTACAO_AES));
byte[] encrypted = cipher.doFinal(passByte);
return new BASE64Encoder().encode(encrypted);
}
public static String decryptAES(String passText)
throws NoSuchAlgorithmException, NoSuchPaddingException,
InvalidKeyException, IllegalBlockSizeException,
BadPaddingException, IOException, InvalidAlgorithmParameterException {
byte[] passByte = passText.getBytes("ISO-8859-1");
Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
cipher.init(Cipher.DECRYPT_MODE, new SecretKeySpec(Crypt.KEY,
Crypt.METODO_ENCRIPTACAO_AES));
byte[] decrypted = cipher.doFinal(passByte);
return Hex.encodeHexString(decrypted);
}