InvalidKeyException java.security.InvalidKeyException: nenhum provedor instalado suporta esta chave: (nulo)
Eu tenho duas classes, uma é a classe principal e outra é a implementação do AES.
No entanto, na minha classe AES, eu tenho um método para descriptografar uma string, mas sempre que eu a executo, isso gera uma exceção
Meu método de criptografia funciona muito bem, mas meu método de descriptografia não funciona conforme o esperado.
O código
private Cipher aesCipherForDecryption;
String strDecryptedText = new String();
public String decryptAES(final String ciphertext) {
try {
aesCipherForDecryption = Cipher.getInstance("AES/CBC/PKCS5PADDING");
aesCipherForDecryption.init(Cipher.DECRYPT_MODE, secretKey, new IvParameterSpec(iV));
byte[] byteDecryptedText = aesCipherForDecryption.doFinal(byteCipherText);
strDecryptedText = new String(byteDecryptedText);
} catch (IllegalBlockSizeException e) {
System.out.print("IllegalBlockSizeException " +e);
} catch (BadPaddingException e) {
System.out.print("BadPaddingException "+e);
} catch (NoSuchAlgorithmException e) {
System.out.print("NoSuchAlgorithmException "+ e);
} catch (NoSuchPaddingException e) {
System.out.print("NoSuchPaddingException "+e);
} catch (InvalidKeyException e) {
System.out.print("InvalidKeyException "+e);
} catch (InvalidAlgorithmParameterException e) {
System.out.print("InvalidAlgorithmParameterException "+e);
}
System.out.println("\nDecrypted Text message is " + strDecryptedText);
return strDecryptedText;
}
O erro que esse método gera é
InvalidKeyException java.security.InvalidKeyException: nenhum provedor instalado suporta esta chave: (nulo)
ATUALIZAÇÃO # 1:
Então, eu atualizei o código da seguinte forma
public String decryptAES(byte[] ciphertext) {
String strDecryptedText = new String();
try {
byte[] byteDecryptedText = aesCipherForDecryption.doFinal(ciphertext);
strDecryptedText = new String(byteDecryptedText);
} catch (IllegalBlockSizeException e) {
System.out.print("IllegalBlockSizeException "+e);
e.printStackTrace();
} catch (BadPaddingException e) {
System.out.print("BadPaddingException "+e);
e.printStackTrace();
}
System.out.println("\nDecrypted Text message is " + strDecryptedText);
return strDecryptedText;
}
e na classe principal eu tenho essa linha
byte [] byteciphertext = ciphertext.getBytes();
apenas para converter a string em bytes
está correto? eu ainda estou tendo
IllegalBlockSizeException javax.crypto.IllegalBlockSizeException: Input length must be multiple of 16 when decrypting with padded cipherjavax.crypto.IllegalBlockSizeException: Input length must be multiple of 16 when decrypting with padded cipher
Alguém poderia me ajudar a corrigir esse problema?
Obrigado.