DES加密时正常,解密时出错了:
java.security.InvalidKeyException: Parameters missingat com.sun.crypto.provider.CipherCore.init(CipherCore.java:469)at com.sun.crypto.provider.DESCipher.engineInit(DESCipher.java:186)at javax.crypto.Cipher.implInit(Cipher.java:805)at javax.crypto.Cipher.chooseProvider(Cipher.java:867)at javax.crypto.Cipher.init(Cipher.java:1252)at javax.crypto.Cipher.init(Cipher.java:1189)
代码如下:
public static void decrypt(){Cipher cipher = decryptCipher = Cipher.getInstance(CIPHER_ALGORITHM);Key key = CipherDES.generateKey(CdkeyGenerator.PASSWORD);cipher.init(Cipher.DECRYPT_MODE, key);byte[] decryptedBytes = cipher.doFinal(validateBytes);}
解决办法:
错误的参数:String CIPHER_ALGORITHM = "DES/CBC/PKCS5Padding";正确的参数:String CIPHER_ALGORITHM = "DES/ECB/PKCS5Padding";
如果觉得《DES解密:java.security.InvalidKeyException: Parameters missing》对你有帮助,请点赞、收藏,并留下你的观点哦!