本文整理汇总了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;
}