soyersoyer / SwCrypt

RSA public/private key generation, RSA, AES encryption/decryption, RSA sign/verify in Swift with CommonCrypto in iOS and OS X
MIT License
718 stars 123 forks source link

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

Open pourang opened 7 years ago

pourang commented 7 years ago

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

Ashok28 commented 7 years ago

Would like to see answer for this too.

pkarc commented 7 years ago

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.                 
*/
soyersoyer commented 6 years ago

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.