How to use the pkijs.ECPrivateKey function in pkijs

To help you get started, we’ve selected a few pkijs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github PeculiarVentures / node-webcrypto-p11 / src / mechs / ec / crypto.ts View on Github external
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),
    };
  }
github PeculiarVentures / node-webcrypto-p11 / lib / crypto / ec.ts View on Github external
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)),
    };
}
github PeculiarVentures / node-webcrypto-p11 / lib / crypto / ec.ts View on Github external
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;
github PeculiarVentures / node-webcrypto-p11 / src / mechs / ec / crypto.ts View on Github external
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;

pkijs

Public Key Infrastructure (PKI) is the basis of how identity and key management is performed on the web today. PKIjs is a pure JavaScript library implementing the formats that are used in PKI applications. It is built on WebCrypto and aspires to make it p

BSD-3-Clause
Latest version published 5 months ago

Package Health Score

80 / 100
Full package analysis