InvalidKeyException java.security.InvalidKeyException: Kein installierter Anbieter unterstützt diesen Schlüssel: (null)
Ich habe zwei Klassen, eine ist Hauptklasse und eine andere ist die Implementierung von AES.
Allerdings habe ich in meiner AES-Klasse eine Methode, um einen String zu entschlüsseln, aber wann immer ich ihn starte, gibt es eine Ausnahme
Meine Verschlüsselungsmethode funktioniert einwandfrei, aber meine Entschlüsselungsmethode funktioniert nicht wie erwartet.
Der Cod
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;
}
Der Fehler, den diese Methode ausgibt, ist
InvalidKeyException java.security.InvalidKeyException: Kein installierter Anbieter unterstützt diesen Schlüssel: (null)
UPDATE # 1:
So habe ich den Code wie folgt aktualisiert
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;
}
und in der Hauptklasse habe ich diese Zeile
byte [] byteciphertext = ciphertext.getBytes();
nur um die Zeichenkette in Bytes umzuwandeln
ist es richtig? Ich habe immer noch
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
Kann mir jemand helfen, dieses Problem zu beheben?
Vielen Dank