java.security.InvalidKeyException:错误的算法:需要DESede或TripleDES
我写了这段代码,我的密钥是:ooWqEPcw7KR/h/jibrfchievaybvnb2java.security.InvalidKeyException:错误的算法:需要DESede或TripleDES,java,encryption,cryptography,3des,Java,Encryption,Cryptography,3des,我写了这段代码,我的密钥是:ooWqEPcw7KR/h/jibrfchievaybvnb2 try { Base64Decoder base64Decoder=new Base64Decoder(); String encryptType="DESede/ECB/PKCS5Padding"; String workingKey="ooWqEPcw7KR/h/JIbrFCRHiEVaybvnB2"; SecretKe
try
{
Base64Decoder base64Decoder=new Base64Decoder();
String encryptType="DESede/ECB/PKCS5Padding";
String workingKey="ooWqEPcw7KR/h/JIbrFCRHiEVaybvnB2";
SecretKey secretKey=new SecretKeySpec(base64Decoder.decode(workingKey), encryptType);
Cipher cipher=Cipher.getInstance(encryptType);
cipher.init(1, secretKey);
}
catch(NoSuchAlgorithmException | NoSuchPaddingException | InvalidKeyException e)
{
e.printStackTrace();
}
但是我得到了这个错误
java.security.InvalidKeyException: Wrong algorithm: DESede or TripleDES required
at com.sun.crypto.provider.DESedeCrypt.init(DESedeCrypt.java:65)
at com.sun.crypto.provider.ElectronicCodeBook.init(ElectronicCodeBook.java:93)
at com.sun.crypto.provider.CipherCore.init(CipherCore.java:582)
at com.sun.crypto.provider.CipherCore.init(CipherCore.java:458)
at com.sun.crypto.provider.DESedeCipher.engineInit(DESedeCipher.java:166)
at javax.crypto.Cipher.implInit(Cipher.java:802)
at javax.crypto.Cipher.chooseProvider(Cipher.java:864)
at javax.crypto.Cipher.init(Cipher.java:1249)
at javax.crypto.Cipher.init(Cipher.java:1186)
at EncryptText.main(EncryptText.java:24)
根据源代码,DeSedCrypt类仅支持DESede和TripleDES算法:
void init(boolean decrypting, String algorithm, byte[] keys)
throws InvalidKeyException {
if (!algorithm.equalsIgnoreCase("DESede")
&& !algorithm.equalsIgnoreCase("TripleDES")) {
throw new InvalidKeyException
("Wrong algorithm: DESede or TripleDES required");
}
您的代码必须使用SecretKey中的两个选项之一。密码可以保留为DESede/ECB/pkcs5p添加:
根据源代码,DeSedCrypt类仅支持DESede和TripleDES算法:
void init(boolean decrypting, String algorithm, byte[] keys)
throws InvalidKeyException {
if (!algorithm.equalsIgnoreCase("DESede")
&& !algorithm.equalsIgnoreCase("TripleDES")) {
throw new InvalidKeyException
("Wrong algorithm: DESede or TripleDES required");
}
您的代码必须使用SecretKey中的两个选项之一。密码可以保留为DESede/ECB/pkcs5p添加:
您应该将SecretKeySpec编写为
SecretKey secretKey=new SecretKeySpec(base64Decoder.decode(workingKey),"DESede");
也可以使用Cipher.ENCRYPT_模式和Cipher.DECRYPT_模式而不是常量。您应该将SecretKeySpec编写为
SecretKey secretKey=new SecretKeySpec(base64Decoder.decode(workingKey),"DESede");
也可以使用Cipher.ENCRYPT_模式和Cipher.DECRYPT_模式,而不是常量。new SecretKeySpeckeyBytes,DESede;注意:使用Cipher.ENCRYPT_模式的1个整数不是一个好主意,请使用constants。我使用了Cipher.ENCRYPT_模式,但不起作用。以上代码在Android Studio中工作。但它在Intellijidead中不起作用。你是否更改了新的SecretKeySpeckeyBytes,DESede?是的。谢谢它对我有用。你节省了我的时间;注意:使用Cipher.ENCRYPT_模式的1个整数不是一个好主意,请使用constants。我使用了Cipher.ENCRYPT_模式,但不起作用。以上代码在Android Studio中工作。但它在Intellijidead中不起作用。你是否更改了新的SecretKeySpeckeyBytes,DESede?是的。谢谢它对我有用。你节省了我的时间。