java.security.NoSuchAlgorithmException: Unsupported secret key algorithm: DES
at com.sun.crypto.provider.DHKeyAgreement.engineGenerateSecret(DHKeyAgreement.java:387)
at javax.crypto.KeyAgreement.generateSecret(KeyAgreement.java:648)
我使用 JDK1.8,这是什么问题?
代码是看视频写的,并且也参考了评论中的部分代码。运行都是这个问题。
由于JDK版本不同,在Java 8 update 161版本以后就会出现此问题,根本原因还是DH密钥长度至少为512位,而DES算法密钥没有这么长,密钥长度不一致引起的。
解决方法:
配置JVM的系统变量:-Djdk.crypto.KeyAgreement.legacyKDF=true
我的也是,怎么解决的 啊!
java.security.NoSuchAlgorithmException: Unsupported secret key algorithm: DES
at com.sun.crypto.provider.DHKeyAgreement.engineGenerateSecret(DHKeyAgreement.java:387)
at javax.crypto.KeyAgreement.generateSecret(KeyAgreement.java:648)
at com.wbs.security.dh.ImoocDH.jdkDH(ImoocDH.java:50)
at com.wbs.security.dh.ImoocDH.main(ImoocDH.java:24)
47 KeyAgreement receiverKeyAgreement = KeyAgreement.getInstance("DH");
48 receiverKeyAgreement.init(receiverPrivateKey);
49 receiverKeyAgreement.doPhase(receiverPublicKey, true);
50 SecretKey receiverDesKey = receiverKeyAgreement.generateSecret("DES");
jdk版本问题
这里的 DES。
//3.密钥构建
KeyAgreement receiveKeyAgreement = KeyAgreement.getInstance("DH");
receiveKeyAgreement.init(receivePrivateKey);
receiveKeyAgreement.doPhase(receivePublicKey, true);
SecretKey receiveDesKey = receiveKeyAgreement.generateSecret("DES");