output public jwk from private pem
This commit is contained in:
parent
a2bfbf2308
commit
6554a8278e
|
@ -16,7 +16,8 @@ try {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ('string' === typeof key) {
|
if ('string' === typeof key) {
|
||||||
eckles.import({ pem: key }).then(function (jwk) {
|
var pub = (-1 !== [ 'public', 'spki', 'pkix' ].indexOf(format));
|
||||||
|
eckles.import({ pem: key, public: (pub || format) }).then(function (jwk) {
|
||||||
console.log(JSON.stringify(jwk, null, 2));
|
console.log(JSON.stringify(jwk, null, 2));
|
||||||
}).catch(function (err) {
|
}).catch(function (err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
|
|
|
@ -244,15 +244,15 @@ EC.parse = function parseEc(opts) {
|
||||||
// PKCS8
|
// PKCS8
|
||||||
if (0x02 === u8[3] && 0x30 === u8[6] && 0x06 === u8[8]) {
|
if (0x02 === u8[3] && 0x30 === u8[6] && 0x06 === u8[8]) {
|
||||||
//console.log("PKCS8", u8[3].toString(16), u8[6].toString(16), u8[8].toString(16));
|
//console.log("PKCS8", u8[3].toString(16), u8[6].toString(16), u8[8].toString(16));
|
||||||
return EC.parsePkcs8(u8, jwk);
|
jwk = EC.parsePkcs8(u8, jwk);
|
||||||
// EC-only
|
// EC-only
|
||||||
} else if (0x02 === u8[2] && 0x04 === u8[5] && 0xA0 === u8[39]) {
|
} else if (0x02 === u8[2] && 0x04 === u8[5] && 0xA0 === u8[39]) {
|
||||||
//console.log("EC---", u8[2].toString(16), u8[5].toString(16), u8[39].toString(16));
|
//console.log("EC---", u8[2].toString(16), u8[5].toString(16), u8[39].toString(16));
|
||||||
return EC.parseSec1(u8, jwk);
|
jwk = EC.parseSec1(u8, jwk);
|
||||||
// SPKI/PKIK (Public)
|
// SPKI/PKIK (Public)
|
||||||
} else if (0x30 === u8[2] && 0x06 === u8[4] && 0x06 === u8[13]) {
|
} else if (0x30 === u8[2] && 0x06 === u8[4] && 0x06 === u8[13]) {
|
||||||
//console.log("SPKI-", u8[2].toString(16), u8[4].toString(16), u8[13].toString(16));
|
//console.log("SPKI-", u8[2].toString(16), u8[4].toString(16), u8[13].toString(16));
|
||||||
return EC.parseSpki(u8, jwk);
|
jwk = EC.parseSpki(u8, jwk);
|
||||||
// Error
|
// Error
|
||||||
} else {
|
} else {
|
||||||
//console.log("PKCS8", u8[3].toString(16), u8[6].toString(16), u8[8].toString(16));
|
//console.log("PKCS8", u8[3].toString(16), u8[6].toString(16), u8[8].toString(16));
|
||||||
|
@ -266,15 +266,15 @@ EC.parse = function parseEc(opts) {
|
||||||
// PKCS8
|
// PKCS8
|
||||||
if (0x02 === u8[3] && 0x30 === u8[6] && 0x06 === u8[8]) {
|
if (0x02 === u8[3] && 0x30 === u8[6] && 0x06 === u8[8]) {
|
||||||
//console.log("PKCS8", u8[3].toString(16), u8[6].toString(16), u8[8].toString(16));
|
//console.log("PKCS8", u8[3].toString(16), u8[6].toString(16), u8[8].toString(16));
|
||||||
return EC.parsePkcs8(u8, jwk);
|
jwk = EC.parsePkcs8(u8, jwk);
|
||||||
// EC-only
|
// EC-only
|
||||||
} else if (0x02 === u8[3] && 0x04 === u8[6] && 0xA0 === u8[56]) {
|
} else if (0x02 === u8[3] && 0x04 === u8[6] && 0xA0 === u8[56]) {
|
||||||
//console.log("EC---", u8[3].toString(16), u8[6].toString(16), u8[56].toString(16));
|
//console.log("EC---", u8[3].toString(16), u8[6].toString(16), u8[56].toString(16));
|
||||||
return EC.parseSec1(u8, jwk);
|
jwk = EC.parseSec1(u8, jwk);
|
||||||
// SPKI/PKIK (Public)
|
// SPKI/PKIK (Public)
|
||||||
} else if (0x30 === u8[2] && 0x06 === u8[4] && 0x06 === u8[13]) {
|
} else if (0x30 === u8[2] && 0x06 === u8[4] && 0x06 === u8[13]) {
|
||||||
//console.log("SPKI-", u8[2].toString(16), u8[4].toString(16), u8[13].toString(16));
|
//console.log("SPKI-", u8[2].toString(16), u8[4].toString(16), u8[13].toString(16));
|
||||||
return EC.parseSpki(u8, jwk);
|
jwk = EC.parseSpki(u8, jwk);
|
||||||
// Error
|
// Error
|
||||||
} else {
|
} else {
|
||||||
//console.log("PKCS8", u8[3].toString(16), u8[6].toString(16), u8[8].toString(16));
|
//console.log("PKCS8", u8[3].toString(16), u8[6].toString(16), u8[8].toString(16));
|
||||||
|
@ -285,6 +285,14 @@ EC.parse = function parseEc(opts) {
|
||||||
} else {
|
} else {
|
||||||
throw new Error("Supported key types are P-256 and P-384");
|
throw new Error("Supported key types are P-256 and P-384");
|
||||||
}
|
}
|
||||||
|
if (opts.public) {
|
||||||
|
if (true !== opts.public) {
|
||||||
|
throw new Error("options.public must be either `true` or `false` not ("
|
||||||
|
+ typeof opts.public + ") '" + opts.public + "'");
|
||||||
|
}
|
||||||
|
delete jwk.d;
|
||||||
|
}
|
||||||
|
return jwk;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
EC.toJwk = EC.import = EC.parse;
|
EC.toJwk = EC.import = EC.parse;
|
||||||
|
|
Loading…
Reference in New Issue