天天看點

java.security.InvalidKeyException: Parameters missing 問題解決

DES解密Parameters missing問題

java.security.InvalidKeyException: Parameters missing
	at com.sun.crypto.provider.CipherCore.init(CipherCore.java:460)
	at com.sun.crypto.provider.DESCipher.engineInit(DESCipher.java:186)
	at javax.crypto.Cipher.implInit(Cipher.java:797)
	at javax.crypto.Cipher.chooseProvider(Cipher.java:859)
	at javax.crypto.Cipher.init(Cipher.java:1229)
	at javax.crypto.Cipher.init(Cipher.java:1166)
	at com.first.start.common.util.crypt.DESUtil.decrypt(DESUtil.java:115)
	at com.first.start.common.util.crypt.TestCrypt.testDES(TestCrypt.java:70)
	at com.first.start.common.util.crypt.TestCrypt.main(TestCrypt.java:13)
           

在嘗試幾種 加密/解密算法-工作模式的時候突然間就報了個參數缺失。

問題解決

CBC的方式和ECB的方式在初始化key的時候參數多一個。開始寫的字元串在其中感覺長得差不多,就沒注意到方式變了,隻改了一部分。是以就整好改造了一下寫成常量了。

java.security.InvalidKeyException: Parameters missing 問題解決

其他相關異常說明

} catch (NoSuchAlgorithmException e) {
		throw new NoSuchAlgorithmException("無此加密算法,請檢查環境");
	} catch (NoSuchPaddingException e) {
		throw new NoSuchPaddingException("明文資料未找到");
	} catch (InvalidKeyException e) {
		throw new InvalidKeyException("加密秘鑰非法,請檢查");
	} catch (IllegalBlockSizeException e) {
		throw new IllegalBlockSizeException("明文長度非法");
	} catch (BadPaddingException e) {
		throw new BadPaddingException("明文資料已損壞");
	} catch (Exception e) {
		e.printStackTrace();
		throw new Exception("其他錯誤:", e);
	}