Search code examples
objective-ccopensslasn.1diffie-hellman

OpenSSL Diffie Hellman DER Encoding in C


I have a problem and spent the last two days searching for an answers.

I generated a DH Object with OpenSSL in C (more specific Objective-C, but I think there isn't something like that) and now can access the p,q and publickey values that are Bignums. I need to send these values as ASN.1 DER Encoding to a server as one base64 string.

On the Android Client the important step is .getPublic().getEncoded() followed by a base64 Encoding. ( is something with a keyagreement or so)

How can I do that on c or objective-c? Code examples would be very very great.


Solution

  • For DER encoding, you can i2d_DHParams may solve your purpose.

    Suppose you have DH parameters in dh, then you can call

      int len;
      len  = i2d_DHParams (dh, &buf);
      //It should write encoded dh to buf and len should be number of bytes written.
    

    You can see DH methods here.