问答详情
源自:2-3 DH算法实现

java.security.NoSuchAlgorithmException: Unsupported secret key algorithm: DES

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,这是什么问题?

代码是看视频写的,并且也参考了评论中的部分代码。运行都是这个问题。

提问者:王二小的宠物狗 2018-05-17 16:08

个回答

  • qq_Insomnic_0
    2018-10-10 15:47:23

    由于JDK版本不同,在Java 8 update 161版本以后就会出现此问题,根本原因还是DH密钥长度至少为512位,而DES算法密钥没有这么长,密钥长度不一致引起的。

    解决方法:

    配置JVM的系统变量:-Djdk.crypto.KeyAgreement.legacyKDF=true

    https://img3.mukewang.com/5bbdae8800016f9210920689.jpg

  • qq_花泽香菜_0
    2018-06-20 21:42:27

    我的也是,怎么解决的 啊!

    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");


  • qq_竹心_2
    2018-06-11 22:50:49

    jdk版本问题

  • 王二小的宠物狗
    2018-05-17 16:22:47

    这里的 DES。

    //3.密钥构建

    KeyAgreement receiveKeyAgreement = KeyAgreement.getInstance("DH");

    receiveKeyAgreement.init(receivePrivateKey);

    receiveKeyAgreement.doPhase(receivePublicKey, true);

    SecretKey receiveDesKey = receiveKeyAgreement.generateSecret("DES");