SwCrypt icon indicating copy to clipboard operation
SwCrypt copied to clipboard

What is the type def of generateKey() in DH class?

Open pourang opened this issue 8 years ago • 3 comments

Hi,

What is the content of NSData that is returned by generateKey() in DH class? How can I convert it (Public Key) to X509 in order to be used by Java consumer?

Best Regards, P

pourang avatar Oct 27 '16 12:10 pourang

Would like to see answer for this too.

Ashok28 avatar Nov 02 '16 16:11 Ashok28

Hope is not too late to reply, as the documentation says at https://opensource.apple.com/source/CommonCrypto/CommonCrypto-60027/Source/CommonCryptoSPI/CommonDH.h

It returns a byte string

/*!
    @function   CCDHGenerateKey
    @abstract   Generate the public key for use in a Diffie-Hellman handshake. 
                This value is returned as a byte string.

    @param      ref  The Diffie-Hellman context.
    @result	returns -1 on failure.                 
*/

pkarc avatar Oct 10 '17 11:10 pkarc

It's an Octet String as defined in PKCS#3.

https://github.com/st3fan/osx-10.9/blob/master/CommonCrypto-60049/lib/CommonDH.c#L124 https://github.com/samdmarshall/apple-corecrypto/blob/df1ffe4ae19dcb7c320d336d7f5f28c9af6daa09/ccdh/corecrypto/ccdh.h#L331

Maybe the java's X509EncodedKeySpec can use it.

soyersoyer avatar Oct 14 '18 00:10 soyersoyer