crypto#createECDH TypeScript Examples
The following examples show how to use
crypto#createECDH.
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 |
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: crypto.ts From FIDO2Client with MIT License | 6 votes |
static regenerate(): IFido2CryptoKey {
switch (Fido2Spec) {
case Fido2SpecVersion.FIDO_2_1: {
let key = createECDH('prime256v1');
key.generateKeys();
return { publicKey: key.getPublicKey(), privateKey: key.getPrivateKey() }
}
default:
throw new CommonFido2SpecNotImplemented();
}
}
Example #3
Source File: crypto.ts From FIDO2Client with MIT License | 6 votes |
static sharedSecretGeneration(privateKey: Buffer, publicKey: Buffer): Buffer {
switch (Fido2Spec) {
case Fido2SpecVersion.FIDO_2_1: {
let key = createECDH('prime256v1');
key.setPrivateKey(privateKey);
return Fido2Crypto.hash(key.computeSecret(publicKey));
}
default:
throw new CommonFido2SpecNotImplemented();
}
}
Example #4
Source File: client-pin.ts From FIDO2Client with MIT License | 5 votes |
initialize(): void {
this.key = createECDH('prime256v1');
this.key.generateKeys();
}
Example #5
Source File: api.ts From eufy-security-client with MIT License | 5 votes |
private ecdh: ECDH = createECDH("prime256v1");