encryption - InvalidKeyException java.security.InvalidKeyException: No installed provider supports this key: (null) -
encryption - InvalidKeyException java.security.InvalidKeyException: No installed provider supports this key: (null) -
i have 2 classes, 1 main class , implementation of aes.
however, in aes class have method decrypt string, whenever run it, gives exception
my encryption method works fine decryption method doesn't work expected.
the code
private cipher aescipherfordecryption; string strdecryptedtext = new string(); public string decryptaes(final string ciphertext) { seek { aescipherfordecryption = cipher.getinstance("aes/cbc/pkcs5padding"); aescipherfordecryption.init(cipher.decrypt_mode, secretkey, new ivparameterspec(iv)); byte[] bytedecryptedtext = aescipherfordecryption.dofinal(byteciphertext); strdecryptedtext = new string(bytedecryptedtext); } grab (illegalblocksizeexception e) { system.out.print("illegalblocksizeexception " +e); } grab (badpaddingexception e) { system.out.print("badpaddingexception "+e); } grab (nosuchalgorithmexception e) { system.out.print("nosuchalgorithmexception "+ e); } grab (nosuchpaddingexception e) { system.out.print("nosuchpaddingexception "+e); } grab (invalidkeyexception e) { system.out.print("invalidkeyexception "+e); } grab (invalidalgorithmparameterexception e) { system.out.print("invalidalgorithmparameterexception "+e); } system.out.println("\ndecrypted text message " + strdecryptedtext); homecoming strdecryptedtext; }
the error method outputs is
invalidkeyexception java.security.invalidkeyexception: no installed provider supports key: (null)
update #1:
so have updated code following
public string decryptaes(byte[] ciphertext) { string strdecryptedtext = new string(); seek { byte[] bytedecryptedtext = aescipherfordecryption.dofinal(ciphertext); strdecryptedtext = new string(bytedecryptedtext); } grab (illegalblocksizeexception e) { system.out.print("illegalblocksizeexception "+e); e.printstacktrace(); } grab (badpaddingexception e) { system.out.print("badpaddingexception "+e); e.printstacktrace(); } system.out.println("\ndecrypted text message " + strdecryptedtext); homecoming strdecryptedtext; }
and in main class have line
byte [] byteciphertext = ciphertext.getbytes();
just convert string bytes
is correct? i'm still having
illegalblocksizeexception javax.crypto.illegalblocksizeexception: input length must multiple of 16 when decrypting padded cipherjavax.crypto.illegalblocksizeexception: input length must multiple of 16 when decrypting padded cipher
could help me prepare issue?
thank you.
secretkey
null.
other problems:
you aren't using input parameterciphertext
. the input parameter ciphertext
should byte[],
not string
: cipher text binary, , string
not container binary data. the result string strdecryptedtext
should local variable, not fellow member variable. java encryption aes
Comments
Post a Comment