crypto#ECDH TypeScript Examples

The following examples show how to use crypto#ECDH. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: utils.ts    From eufy-security-client with MIT License 7 votes vote down vote up
getAdvancedLockKey = (key: string, publicKey: string): string => {
    const ecdh: ECDH = createECDH("prime256v1");
    ecdh.generateKeys();
    const secret = ecdh.computeSecret(Buffer.concat([Buffer.from("04", "hex"), Buffer.from(publicKey, "hex")]));
    const randomValue = randomBytes(16);

    const derivedKey = eufyKDF(secret);
    const encryptedData = encryptAdvancedLockData(key, derivedKey.slice(0, 16), randomValue);

    const hmac = createHmac("sha256", derivedKey.slice(16));
    hmac.update(randomValue);
    hmac.update(encryptedData);
    const hmacDigest = hmac.digest();

    return Buffer.concat([Buffer.from(ecdh.getPublicKey("hex", "compressed"), "hex"), randomValue, encryptedData, hmacDigest]).toString("hex");
}
Example #2
Source File: client-pin.ts    From FIDO2Client with MIT License 5 votes vote down vote up
private key!: ECDH;
Example #3
Source File: api.ts    From eufy-security-client with MIT License 5 votes vote down vote up
private ecdh: ECDH = createECDH("prime256v1");