encryption - How to read a public key from a pem file using BIO from openssl? -


i'm using openssl library , want read public key .pem file bio. tried this, rsa variable remains uninitialized :

 rsa *rsa = rsa_new();   bio *keybio = null;   keybio = bio_new(bio_s_file());  bio_read_filename(keybio, "public.pem");   // , tried instead of last 2 lines:  // keybio = bio_new_file("public.rem", "r");   rsa = pem_read_bio_rsa_pubkey(keybio, &rsa, null, null); 

when debug application shows me this:

rsa { padding = ???, n = ??? , ...}  rsa->n <unable read memory> , on rsa fields. 

my file valid , key generated respecting pkcs#1 format. parsed asn1 parser.

your code looks fine. try input:

-----begin public key----- miibijanbgkqhkig9w0baqefaaocaq8amiibcgkcaqea1ihyytavz9pqrxpcyo7j m0dtiijnuvw3colqqkhq+wysttn1cwm2zytw0fsfldpotobnxfwkf9wykiyhs2uu d8viu+t/fvlcadyttzqdc5aobwlsuhp0xqqthmnuejga4fprmkusl8s5/cuafnrv nvsxa3jcn3kyrt9q1qbn+xboqn+h7gpqu3icmg7l1r/cwisq/wwubq+ney0tmvz5 lm6ais+gcv0uejvm6un6gdbcohk02xuplyhkbcsnhq+htfhhvee1s7nciavmgvqm etlictgemw9txs5/rezuv+sdpr6rlukhwuij/ft5pe9b7ch3wxqnmobhj3f/ht2c swidaqab -----end public key----- 

compare see asn1 parser:

$ openssl asn1parse -in public.pem     0:d=0  hl=4 l= 290 cons: sequence               4:d=1  hl=2 l=  13 cons: sequence               6:d=2  hl=2 l=   9 prim: object            :rsaencryption    17:d=2  hl=2 l=   0 prim: null                  19:d=1  hl=4 l= 271 prim: bit string         

Comments

Popular posts from this blog

apache - PHP Soap issue while content length is larger -

asynchronous - Python asyncio task got bad yield -

javascript - Complete OpenIDConnect auth when requesting via Ajax -