How to get AES secret key from DH secret key

前端 未结 2 1909
挽巷
挽巷 2021-01-23 18:47

I have the following code that converts a DH secret key to AES secret key. This used to work until Oracle JRE 8u161 when they started restricting creation of DH keys < 1024 i

2条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-23 19:08

    The problem with Oracle/Sun-providers is not the DH keysize limitation in java.security, which only applies to TLS/SSL (i.e. JSSE), but this item slightly further down in the release notes you linked:

    • Stricter key generation

    The generateSecret(String) method has been mostly disabled in the javax.crypto.KeyAgreement services of the SunJCE and SunPKCS11 providers. Invoking this method for these providers will result in a NoSuchAlgorithmException for most algorithm string arguments. The previous behavior of this method can be re-enabled by setting the value of the jdk.crypto.KeyAgreement.legacyKDF system property to true (case insensitive). Re-enabling this method by setting this system property is not recommended.

    The next paragraphs basically say, not very clearly, that using DH correctly requires a suitable KDF, but this operation doesn't provide/define the KDF, so it can't ensure suitability, and instead you should use the no-argument generateSecretKey() method to get the raw DH value and apply a suitable KDF yourself; they give SP800-56Ar2 and plain hash as examples.

    BouncyCastle went the other way; in 1.60 it has several KeyAgreement algorithms with the KDF encoded like DHwithSHA256CKDF.

提交回复
热议问题