// 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
);
使用
AlgorithmParameters来自加密的
Cipher:
cipherDecrypt.init( Cipher.DECRYPT_MODE, key, cipherEncrypt.getParameters() );
如果您想要一种不涉及
cipherEncrypt解密站点的更简洁的方法,请将算法参数另存为字节,然后将其与密钥数据一起传输:
byte[] algorithmParametersEnpred = cipherEncrypt.getParameters().getEnpred();
并在解密站点将其重建:
AlgorithmParameters algorithmParameters = AlgorithmParameters.getInstance(ALGORITHM);algorithmParameters.init(algorithmParametersEnpred);
并
algorithmParameters用作上述
parameters参数
Cipher.init()。



