本文整理匯總了TypeScript中crypto.ECDH類的典型用法代碼示例。如果您正苦於以下問題:TypeScript ECDH類的具體用法?TypeScript ECDH怎麽用?TypeScript ECDH使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了ECDH類的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1:
N: 16384,
r: 8,
p: 1,
maxmem: 32 * 1024 * 1024
};
crypto.scrypt(pwd, salt, 64, opts, (err: Error | null, derivedKey: Buffer): void => {});
crypto.scrypt(pwd, salt, 64, { maxmem: 16 * 1024 * 1024 }, (err: Error | null, derivedKey: Buffer): void => {});
let buf: Buffer = crypto.scryptSync(pwd, salt, 64);
buf = crypto.scryptSync(pwd, salt, 64, opts);
buf = crypto.scryptSync(pwd, salt, 64, { N: 1024 });
}
{
let key: string | Buffer = Buffer.from("buf");
const curve = "secp256k1";
let ret: string | Buffer = crypto.ECDH.convertKey(key, curve);
key = "0xfff";
ret = crypto.ECDH.convertKey(key, curve);
ret = crypto.ECDH.convertKey(key, curve, "hex");
ret = crypto.ECDH.convertKey(key, curve, "hex", "hex");
ret = crypto.ECDH.convertKey(key, curve, "hex", "hex", "uncompressed");
ret = crypto.ECDH.convertKey(key, curve, "hex", "hex", "compressed");
ret = crypto.ECDH.convertKey(key, curve, "hex", "hex", "hybrid");
}
{
const rsaRes: {
publicKey: Buffer;
privateKey: string;
} = crypto.generateKeyPairSync('rsa', {
modulusLength: 123,
示例2: constructor
/**
* @param privKey The 3-part tiForms private key, in the form:
* `base64URL(x)|base64URL(y)|base64URL(d)`
*/
constructor(privKey: string) {
const keyParts = privKey.split("|");
const dBase64 = Base64.makeStandard(keyParts[2]);
this.privKey = createECDH("prime256v1");
this.privKey.setPrivateKey(dBase64, 'base64');
}
示例3: decryptString
decryptString(data: EncryptedData): string
{
const
secret = this.privKey.computeSecret(pubKeyToBuffer(data.pubKey)),
iv = Buffer.alloc(16, 0),
cipher = createDecipheriv("aes-256-cbc", secret, iv);
let decrypted = cipher.update(data.payload, "base64", "utf8");
decrypted += cipher.final("utf8");
return decrypted;
}