热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

Node.js中的椭圆曲线Diffie-Hellman密钥交换方法`crypto.createECDH()`使用详解

Node.js crypto.createECDH()方法原文:https://www . geesforgeks . org/

Node.js crypto.createECDH()方法

原文:https://www . geesforgeks . org/node-js-crypto-createecdh-method/

crypto.createECDH()方法是加密模块的内置应用编程接口,用于借助于由曲线名称字符串定义的预定义曲线来创建椭圆曲线差分-赫尔曼即(ECDH)密钥交换对象。此外,您可以使用 crypto.getCurves()方法来返回可用曲线名称的列表。

语法:

crypto.createECDH( curveName )

参数:该方法接受单参数曲线名称,类型为字符串。

返回值:返回 ECDH 密钥交换对象。

下面的例子说明了 crypto.createECDH()方法在 Node.js 中的使用:

例 1:

// Node.js program to demonstrate the 
// crypto.createECDH() method
// Including crypto module
const crypto = require('crypto');
// Creating ECDH with curve name
const curv = crypto.createECDH('secp521r1');
// Prints keys
console.log(curv.generateKeys());

输出:


例 2:

// Node.js program to demonstrate the 
// crypto.createECDH() method
// Including crypto module
const crypto = require('crypto');
// Creating ECDH with curve name
const curv = crypto.createECDH('secp521r1');
curv.generateKeys();
// Prints Public key
console.log("Public Key: ", curv.getPublicKey());
// Prints Private Key
console.log("Private Key :", curv.getPrivateKey());

输出:

Public Key:
Private Key :

参考:https://nodejs . org/API/crypt . html # crypt _ crypt _ create ecdh _ curve name


推荐阅读
author-avatar
公民不是百姓2
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有