Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
case "1.2.840.10045.3.1.7": // P-256
crvName = "P-256";
break;
case "1.3.132.0.34": // P-384
crvName = "P-384";
break;
case "1.3.132.0.35": // P-521
crvName = "P-521";
break;
default:
throw new Error(`Unsupported EC named curve '${crvName}'`);
}
const asn1PrvKey = Asn1Js.fromBER(pkcs8.privateKey.valueBlock.valueHex);
const parsedKey = new pkijs.ECPrivateKey({
namedCurve: algId === "1.3.132.0.10" ? "1.2.840.10045.3.1.7" : algId,
schema: asn1PrvKey.result,
});
return {
kty: "EC",
crv: crvName,
d: Convert.ToBase64Url(parsedKey.privateKey.valueBlock.valueHex),
};
}
case "1.2.840.10045.3.1.7": // P-256
crvName = "P-256";
break;
case "1.3.132.0.34": // P-384
crvName = "P-384";
break;
case "1.3.132.0.35": // P-521
crvName = "P-521";
break;
default:
throw new Error(`Unsupported EC named curve '${crvName}'`);
}
const asn1PrvKey = Asn1Js.fromBER(pkcs8.privateKey.valueBlock.valueHex);
const parsedKey = new ECPrivateKey({
namedCurve: algId === "1.3.132.0.10" ? "1.2.840.10045.3.1.7" : algId,
schema: asn1PrvKey.result,
});
return {
kty: "EC",
crv: crvName,
d: Base64Url.encode(new Uint8Array(parsedKey.privateKey.valueBlock.valueHex)),
};
}
function jwk2pkcs(jwk: JsonWebKey): ArrayBuffer {
const parsedKey = new ECPrivateKey();
let coordinateLength = 0;
if ("crv" in jwk) {
switch (jwk.crv.toUpperCase()) {
case "K-256":
parsedKey.namedCurve = "1.3.132.0.10";
coordinateLength = 32;
break;
case "P-256":
parsedKey.namedCurve = "1.2.840.10045.3.1.7";
coordinateLength = 32;
break;
case "P-384":
parsedKey.namedCurve = "1.3.132.0.34";
coordinateLength = 48;
break;
protected static jwk2pkcs(jwk: JsonWebKey): ArrayBuffer {
const parsedKey = new pkijs.ECPrivateKey();
let coordinateLength = 0;
if ("crv" in jwk) {
switch (jwk.crv.toUpperCase()) {
case "K-256":
parsedKey.namedCurve = "1.3.132.0.10";
coordinateLength = 32;
break;
case "P-256":
parsedKey.namedCurve = "1.2.840.10045.3.1.7";
coordinateLength = 32;
break;
case "P-384":
parsedKey.namedCurve = "1.3.132.0.34";
coordinateLength = 48;
break;