c - Openssl how to find out what the bit size of the public key in an X509 certificate is -
if have x509*
openssl has provided me, what's best way figure out bit-ness of rsa public key in certificate? can't quite figure out. i'm pretty sure if i'm in ssl certificate verification callback, can x509 ptr with
x509 * cert = x509_store_ctx_get_current_cert(the_x509_store_ctx);
and surmise public key this
evp_pkey *public_key = x509_get_pubkey(cert);
and need check whether it's rsa, presumably?
if (public_key && (evp_pkey_rsa == public_key->type))
and once know got public key , it's rsa, i'd this:
int key_length = bn_num_bits(public_key->pkey.rsa->n);
but i've found while works quite nicely on openssl 0.9.8, on 1.0.1h segfaults on windows. bignum 'n' doesn't seem valid - data ptr in has garbage pointer.
any idea what's wrong?
as suggested, rsa modulus size in bytes (so not "bit size"...) use:
evp_pkey * public_key = x509_get_pubkey(cert); rsa *rsa_key = evp_pkey_get1_rsa(public_key); int key_length = rsa_size(rsa_key); ... rsa_free(rsa_key);
Comments
Post a Comment