cryptography - Are private key and public key extracted from key pair are of same length using openssl -
when below function used generate rsa key pair of 1024 bits.
rsa_key = rsa_generate_key ( 1024, 3, null, null ); keypair = bio_new ( bio_s_mem ( ) ); pem_write_bio_rsaprivatekey(keypair, rsa_key, null, null, 0, null, null); keypair_len = bio_pending(keypair);
then keypair_len obtained not 1024, 882. reason got reduced.
by using rsa_generate_key() function generating key pair or private key. if when extract private , public keys generating private , public keys of different lengths.
evp_key = evp_pkey_new(); ret = evp_pkey_assign_rsa ( evp_key, rsa_key ); pri = bio_new ( bio_s_mem ( ) ); pub = bio_new ( bio_s_mem ( ) ); pem_write_bio_privatekey ( pri, evp_key, null, null, 0, null, null ); pem_write_bio_pubkey ( pub, evp_key ); pri_len = bio_pending(pri); pub_len = bio_pending(pub);
the lengths of pri_len pub_len 916 , 272 respectively. can in understanding reason why so?
you generate rsa key of modulus size 1024 bits , not bytes. private key contains public key information in representation (be der or pem) larger.
the results you're obtaining not these modulus sizes, sizes of asn.1 structure encoded in pem. -----begin public key-----
stuff.
more on here: https://tls.mbed.org/kb/cryptography/asn1-key-structures-in-der-and-pem
Comments
Post a Comment