Created
September 12, 2017 23:02
-
-
Save venik/a9c02e065adaf13be4dba4b305869e93 to your computer and use it in GitHub Desktop.
jsrsasign doesnt support creating RSA object from public in the ASN.1 form, one needs to extract modulus and exponent manually (typescript)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
// https://crypto.stackexchange.com/questions/18031/how-to-find-modulus-from-a-rsa-public-key/18034#18034 | |
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