Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
crvName = "K-256";
break;
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 parsedKey = new pkijs.ECPublicKey({
namedCurve: algId === "1.3.132.0.10" ? "1.2.840.10045.3.1.7" : algId,
schema: spki.subjectPublicKey.valueBlock.valueHex,
});
return {
kty: "EC",
crv: crvName,
x: Convert.ToBase64Url(parsedKey.x),
y: Convert.ToBase64Url(parsedKey.y),
};
}
crvName = "K-256";
break;
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 parsedKey = new ECPublicKey({
namedCurve: algId === "1.3.132.0.10" ? "1.2.840.10045.3.1.7" : algId,
schema: spki.subjectPublicKey.valueBlock.valueHex,
});
return {
kty: "EC",
crv: crvName,
x: Base64Url.encode(new Uint8Array(parsedKey.x)),
y: Base64Url.encode(new Uint8Array(parsedKey.y)),
};
}
protected static jwk2spki(jwk: JsonWebKey) {
const parsedKey = new pkijs.ECPublicKey();
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;
function jwk2spki(jwk: JsonWebKey) {
const parsedKey = new ECPublicKey();
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;