Skip to content

Instantly share code, notes, and snippets.

@venik venik/rsafrompub.ts
Created Sep 12, 2017

What would you like to do?
jsrsasign doesnt support creating RSA object from public in the ASN.1 form, one needs to extract modulus and exponent manually (typescript)
function getRsaFromPubKey(pubKeyB64: string): RSAKey {
const pubKeyDecoded = b64tohex(pubKeyB64);
// jsrsasign cannot build key out of PEM or ASN.1 string, so we have to extract modulus and exponent
// you can get some idea what happens from the link below (keep in mind that in JS every char is 2 bytes)
const modulus = pubKeyDecoded.substr(50, 128);
const exp = pubKeyDecoded.substr(182, pubKeyDecoded.length);
return KEYUTIL.getKey({n: modulus, e: exp});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.