|
|
@ -19,7 +19,7 @@ RSA.parse = function parseRsa(opts) { |
|
|
|
var pem = opts.pem; |
|
|
|
var block = PEM.parseBlock(pem); |
|
|
|
//var hex = toHex(u8);
|
|
|
|
var jwk = { kty: 'RSA' }; |
|
|
|
var jwk = { kty: 'RSA', n: null, e: null }; |
|
|
|
var asn1 = ASN1.parse(block.der); |
|
|
|
|
|
|
|
var meta = x509.guess(block.der, asn1); |
|
|
@ -82,6 +82,31 @@ RSA.parsePkcs1 = function parseRsaPkcs1(buf, asn1, jwk) { |
|
|
|
}; |
|
|
|
|
|
|
|
RSA.parsePkcs8 = function parseRsaPkcs8(buf, asn1, jwk) { |
|
|
|
console.log(asn1); |
|
|
|
if (2 === asn1.children.length |
|
|
|
&& 0x03 === asn1.children[1].type |
|
|
|
&& 0x30 === asn1.children[1].value[0]) { |
|
|
|
|
|
|
|
asn1 = ASN1.parse(asn1.children[1].value); |
|
|
|
jwk.n = Enc.bufToUrlBase64(asn1.children[0].value); |
|
|
|
jwk.e = Enc.bufToUrlBase64(asn1.children[1].value); |
|
|
|
|
|
|
|
} else if (3 === asn1.children.length |
|
|
|
&& 0x04 === asn1.children[2].type |
|
|
|
&& 0x30 === asn1.children[2].children[0].type |
|
|
|
&& 0x02 === asn1.children[2].children[0].children[0].type) { |
|
|
|
|
|
|
|
asn1 = asn1.children[2].children[0]; |
|
|
|
jwk.n = Enc.bufToUrlBase64(asn1.children[1].value); |
|
|
|
jwk.e = Enc.bufToUrlBase64(asn1.children[2].value); |
|
|
|
jwk.d = Enc.bufToUrlBase64(asn1.children[3].value); |
|
|
|
jwk.p = Enc.bufToUrlBase64(asn1.children[4].value); |
|
|
|
jwk.q = Enc.bufToUrlBase64(asn1.children[5].value); |
|
|
|
jwk.dp = Enc.bufToUrlBase64(asn1.children[6].value); |
|
|
|
jwk.dq = Enc.bufToUrlBase64(asn1.children[7].value); |
|
|
|
jwk.qi = Enc.bufToUrlBase64(asn1.children[8].value); |
|
|
|
|
|
|
|
} else { |
|
|
|
throw new Error("not an RSA PKCS#8 public or private key (wrong format)"); |
|
|
|
} |
|
|
|
return jwk; |
|
|
|
}; |
|
|
|