Method: OpenSSL::PKey::DH#to_der

Defined in:
ossl_pkey_dh.c

#to_deraString

Serializes the DH parameters to a DER-encoding

Note that any existing per-session public/private keys will not get encoded, just the Diffie-Hellman parameters will be encoded.

See also #public_to_der (X.509 SubjectPublicKeyInfo) and #private_to_der (PKCS #8 PrivateKeyInfo or EncryptedPrivateKeyInfo) for serialization with the private or public key components.



267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
# File 'ossl_pkey_dh.c', line 267

static VALUE
ossl_dh_to_der(VALUE self)
{
    OSSL_3_const DH *dh;
    unsigned char *p;
    long len;
    VALUE str;

    GetDH(self, dh);
    if((len = i2d_DHparams(dh, NULL)) <= 0)
  ossl_raise(eDHError, NULL);
    str = rb_str_new(0, len);
    p = (unsigned char *)RSTRING_PTR(str);
    if(i2d_DHparams(dh, &p) < 0)
  ossl_raise(eDHError, NULL);
    ossl_str_adjust(str, p);

    return str;
}