[openssl-users] Generating unsigned RSA Public Key with openssl
ian.bilek at gmail.com
Sun Mar 25 00:32:22 UTC 2018
Following code is simplified to demonstrate plain RSA public key with the
RSA_ptr rsa(RSA_new(), ::RSA_free);
BN_ptr bn(BN_new(), ::BN_free);
BN_set_word(bn.get(), RSA_F4); //65535
RSA_generate_key_ex(rsa.get(), 320, bn.get(), NULL);
BIO * keybio = BIO_new(BIO_s_mem());
char buffer2 ;
size_t pubKeyBufferSize = BIO_read (keybio, buffer2, 320);
std::cout << Convert::BinToHexString(buffer2, pubKeyBufferSize);
//using here our internal routine to print binary data
Output from this will come up with binary data in DER ANS.1 format like
30 02 29 ;SEQUENCE + size
00 ;leading zero of INTEGER
02 03 ;SEQUENCE + size
Now, the "leading zero of INTEGER" part is present to indicate that
following value is positive value integer. However I need to get rid of it
due to some legacy reasons.
I was going through openssl source and found that through the DER
construction its presence is decided based on ASN1_VALUE->type &
V_ASN1_NEG, but I am unable to track down where to set generated PublicKey
as V_ASN1_NEG (or influence it to be generated as negative).
Other way to handle this is to write my own TLV-DER parser and re-pack
these few bytes to comply with what I need, but I would rather enforce API
to do that for me, if it makes sense.
Would you have any advice on this?
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the openssl-users