Method: OpenSSL::PKey::RSA#to_der
- Defined in:
- ossl_pkey_rsa.c
#to_der ⇒ DER-format String
Outputs this keypair in DER encoding.
386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 |
# File 'ossl_pkey_rsa.c', line 386
static VALUE
ossl_rsa_to_der(VALUE self)
{
RSA *rsa;
const BIGNUM *n, *e, *d, *p, *q, *dmp1, *dmq1, *iqmp;
int (*i2d_func)(const RSA *, unsigned char **);
unsigned char *ptr;
long len;
VALUE str;
GetRSA(self, rsa);
RSA_get0_key(rsa, &n, &e, &d);
RSA_get0_factors(rsa, &p, &q);
RSA_get0_crt_params(rsa, &dmp1, &dmq1, &iqmp);
if (n && e && d && p && q && dmp1 && dmq1 && iqmp)
i2d_func = i2d_RSAPrivateKey;
else
i2d_func = (int (*)(const RSA *, unsigned char **))i2d_RSA_PUBKEY;
if((len = i2d_func(rsa, NULL)) <= 0)
ossl_raise(eRSAError, NULL);
str = rb_str_new(0, len);
ptr = (unsigned char *)RSTRING_PTR(str);
if(i2d_func(rsa, &ptr) < 0)
ossl_raise(eRSAError, NULL);
ossl_str_adjust(str, ptr);
return str;
}
|