// PROBLEM: If I pass "ivParamSpec", I get "java.security.InvalidAlgorithmParameterException: Wrong parameter type: PBE expected" // Whereas if I pass pbeParamSpec, I get "java.security.InvalidAlgorithmParameterException: Missing parameter type: IV expected" // What to do? cipherDecrypt.init( Cipher.DECRYPT_MODE, key, ivParamSpec //pbeParamSpec );
Use AlgorithmParameters from Cipher Encryption:
cipherDecrypt.init( Cipher.DECRYPT_MODE, key, cipherEncrypt.getParameters() );
If you need a cleaner method that does not include cipherEncrypt on the decryption site, save the algorithm parameters as a byte and pass them along with the key data:
byte[] algorithmParametersEncoded = cipherEncrypt.getParameters().getEncoded();
and restore them to the decryption site, thus:
AlgorithmParameters algorithmParameters = AlgorithmParameters.getInstance(ALGORITHM); algorithmParameters.init(algorithmParametersEncoded);
and use AlgorithmParameters as the arguments argument to Cipher.init() above.
source share