0

IdPs like Okta are providing public key and exponent in this format.

"n":"sNwO2gzGvmmQH8BKFa--JbsaQrEY7hg9YrJ3lqs_t36cd6EJInE3W0EbmdAHWbZC4-AeMS73BZQsaJqa2UvqWfUTwpVrEVlPOHc0_Tc4VTqLsmuoPaByYOgz5hn3Z_0gYfPq8eGIYuh6QLvKkuYdAWr5yMK0xDof2eFmQ-BoSMjiB4id_c2BjX_TlqxHCDoXtwCD-51R2ZFTNP9PW2ivunDmAD4RCuLjHxnjiB-GmJFGX0KwTp71Ppyd8MYcUFi_ExxOFDWtOqyPzBhWVX0NmxvvujTAUdTa90u29UE0g59W1tbhKQH8LzakWlpaopkqhfDZxeKCo9dDrYhw5NQ1ow"

"e":"AQAB"
    

Can someone tell me how do I decode the exponent 'AQAB' programmatically to a valid value which can be given as input to RSA structure in C/C++ language? I know AQAB decodes to 010001 in hex but I am looking for a sample in c/c++ sample to do that.

After that I can do:

RSA* rsa = RSA_new();
rsa->e = e;
rsa->n = n;
char* lPublic = BIO_new(BIO_s_mem());
PEM_write_bio_RSAPublicKey(lPublic, rsa);
Maarten Bodewes
  • 90,524
  • 13
  • 150
  • 263
Satish Burnwal
  • 487
  • 1
  • 4
  • 11
  • It appears to be base64url encoding (though I'm not 100% sure); which basically means each character represents 6 bits of data (https://en.m.wikipedia.org/wiki/Base64), noting that "+" and "/" in typical base64 encoding are replaced with "-" and "_". You should be able to find a library or write the parser yourself as it's not too hard. – Unn Jul 09 '21 at 06:31
  • @Unn It's called [base64url](https://datatracker.ietf.org/doc/html/rfc4648#page-7). Satish, try e.g. [this question](https://stackoverflow.com/q/57292210/589259). – Maarten Bodewes Jul 09 '21 at 08:30

0 Answers0