<div dir="ltr"><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:12.8px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">Hi,</span><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:12.8px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial"><br></div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:12.8px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial"><div>Following code is simplified to demonstrate plain RSA public key with the OpenSSL library:</div><div><br></div><div>    RSA_ptr rsa(RSA_new(), ::RSA_free);</div><div>    BN_ptr bn(BN_new(), ::BN_free);</div><div>    BN_set_word(bn.get(), RSA_F4);  //65535</div><div>    RSA_generate_key_ex(rsa.get(), 320, bn.get(), NULL);</div><div>    BIO * keybio = BIO_new(BIO_s_mem());</div><div>    i2d_RSAPublicKey_bio(keybio, rsa.get());</div><div>    char buffer2 [2048];</div><div>    size_t pubKeyBufferSize = BIO_read (keybio, buffer2, 320);</div><div>    std::cout << Convert::BinToHexString(<wbr>buffer2, pubKeyBufferSize); //using here our internal routine to print binary data</div><div><br></div><div>Output from this will come up with binary data in DER ANS.1 format like this:</div><div><br></div><div>    30 ;SEQUENCE</div><div>      30 02 29 ;SEQUENCE + size</div><div>        00 ;leading zero of INTEGER</div><div>        CCEE6526AE9D4380B670A23F55B840<wbr>F8C5D8CC784E06E123C126753525FD<wbr>FE1949...</div><div>      02 03 ;SEQUENCE + size</div><div>        010001</div><div><br></div><div>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.</div><div><br></div><div>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).</div><div><br></div><div>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.</div><div><br></div><div>Would you have any advice on this?</div><div><br></div></div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:12.8px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial">Thank you,<br>Jan</div></div>