How to use the graphene-pk11.EcdhParams function in graphene-pk11

To help you get started, we’ve selected a few graphene-pk11 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 / graphene / test / graphene-pk11-tests.ts View on Github external
// generate EC key
    let keys = session.generateKeyPair(graphene.KeyGenMechanism.ECDSA, {
        keyType: graphene.KeyType.ECDSA,
        token: false,
        derive: true,
        paramsECDSA: graphene.NamedCurve.getByName("secp192r1").value
    }, {
            keyType: graphene.KeyType.ECDSA,
            token: false,
            derive: true
        });

    // derive algorithm
    let alg = {
        name: "ECDH1_DERIVE",
        params: new graphene.EcdhParams(
            graphene.EcKdf.SHA1,
            null,
            keys.publicKey.getAttribute({ pointEC: null }).pointEC)
    };

    // Template for derived key
    let template = {
        "class": graphene.ObjectClass.SECRET_KEY,
        "token": false,
        "keyType": graphene.KeyType.AES,
        "valueLen": 256 / 8,
        "encrypt": true,
        "decrypt": true
    };

    // Key derivation
github PeculiarVentures / node-webcrypto-p11 / src / mechs / ec / ec_dh.ts View on Github external
const template: graphene.ITemplate = {
        token: false,
        sensitive: false,
        class: graphene.ObjectClass.SECRET_KEY,
        keyType: graphene.KeyType.GENERIC_SECRET,
        extractable: true,
        encrypt: true,
        decrypt: true,
        valueLen: valueLen >> 3,
      };
      // derive key
      const ecPoint = (algorithm.public as EcCryptoKey).key.getAttribute({ pointEC: null }).pointEC!;
      this.crypto.session.deriveKey(
        {
          name: "ECDH1_DERIVE",
          params: new graphene.EcdhParams(
            graphene.EcKdf.NULL,
            null as any,
            ecPoint, // CKA_EC_POINT
          ),
        },
        baseKey.key,
        template,
        (err, key) => {
          if (err) {
            reject(err);
          } else {
            const secretKey = key.toType();
            const value = secretKey.getAttribute({ value: null }).value as Buffer;
            resolve(new Uint8Array(value.slice(0, length >> 3)).buffer);
          }
        });
github PeculiarVentures / node-webcrypto-p11 / lib / crypto / ec.ts View on Github external
return new Promise((resolve, reject) => {

                    const template = aes.create_template(session!, derivedKeyType, extractable, keyUsages);
                    template.valueLen = derivedKeyType.length >> 3;
                    // derive key
                    session!.deriveKey(
                        {
                            name: "ECDH1_DERIVE",
                            params: new graphene.EcdhParams(
                                EcKdf.NULL,
                                null as any,
                                (algorithm.public as CryptoKey).key.getAttribute({ pointEC: null }).pointEC!, // CKA_EC_POINT
                            ),
                        },
                        baseKey.key,
                        template,
                        (err, key) => {
                            if (err) {
                                reject(err);
                            } else {
                                resolve(new CryptoKey(key, derivedKeyType));
                            }
                        });
                });
            });