静态方法:ECDH.convertKey(key, curve[, inputEncoding[, outputEncoding[, format]]])
添加于:v10.0.0
参数
key<string> | <ArrayBuffer> | <Buffer> | <TypedArray> | <DataView>curve<string>inputEncoding<string>key字符串的encoding。outputEncoding<string> 返回值的encoding。format<string> 默认:'uncompressed'- 返回: <Buffer> | <string>
 
将 key 和 curve 指定的 EC Diffie-Hellman 公钥转换为 format 指定的格式。 format 参数指定点编码,可以是 'compressed' 、 'uncompressed' 或 'hybrid' 。提供的 key 使用指定的 inputEncoding 进行解释,返回的 key 使用指定的 outputEncoding 进行编码。
使用  获取可用曲线名称的列表。在最近的OpenSSL 版本中,crypto.getCurves() openssl ecparam -list_curves 还将显示每个可用椭圆曲线的名称和说明。
如果未指定format,则该点将以'uncompressed' 格式返回。
如果未提供 inputEncoding,则 key 应为   、 Buffer TypedArray 或 DataView 。
示例(解压缩 key ):
const { createECDH, ECDH } = await import('node:crypto'); const ecdh = createECDH('secp256k1'); ecdh.generateKeys(); const compressedKey = ecdh.getPublicKey('hex', 'compressed'); const uncompressedKey = ECDH.convertKey(compressedKey, 'secp256k1', 'hex', 'hex', 'uncompressed'); // The converted key and the uncompressed public key should be the same console.log(uncompressedKey === ecdh.getPublicKey('hex'));const { createECDH, ECDH, } = require('node:crypto'); const ecdh = createECDH('secp256k1'); ecdh.generateKeys(); const compressedKey = ecdh.getPublicKey('hex', 'compressed'); const uncompressedKey = ECDH.convertKey(compressedKey, 'secp256k1', 'hex', 'hex', 'uncompressed'); // The converted key and the uncompressed public key should be the same console.log(uncompressedKey === ecdh.getPublicKey('hex'));
相关用法
- Node.js ECDH.setPublicKey(publicKey[, encoding])用法及代码示例
 - Node.js ECDH用法及代码示例
 - Node.js EventEmitter用法及代码示例
 - Node.js Error.message用法及代码示例
 - Node.js Error.stack用法及代码示例
 - Node.js Error.captureStackTrace(targetObject[, constructorOpt])用法及代码示例
 - Node.js EventTarget.addEventListener(type, listener[, options])用法及代码示例
 - Node.js ServerHttp2Stream http2stream.pushStream(headers[, options], callback)用法及代码示例
 - Node.js http2.Http2ServerRequest request.url用法及代码示例
 - Node.js request.socket用法及代码示例
 - Node.js assert.notEqual(actual, expected[, message])用法及代码示例
 - Node.js tlsSocket.authorized用法及代码示例
 - Node.js zlib.deflateRaw()用法及代码示例
 - Node.js http.IncomingMessage message.rawHeaders用法及代码示例
 - Node.js Console用法及代码示例
 - Node.js GM transparent()用法及代码示例
 - Node.js URL.protocol用法及代码示例
 - Node.js http.Agent.reuseSocket(socket, request)用法及代码示例
 - Node.js fs.filehandle.datasync()用法及代码示例
 - Node.js socket.bind()用法及代码示例
 - Node.js v8.getHeapSpaceStatistics()用法及代码示例
 - Node.js http2session.destroyed用法及代码示例
 - Node.js http.ServerResponse response.statusCode用法及代码示例
 - Node.js Buffer buf.writeBigUInt64BE(value[, offset])用法及代码示例
 - Node.js Http2ServerResponse.finished用法及代码示例
 
注:本文由纯净天空筛选整理自nodejs.org大神的英文原创作品 ECDH.convertKey(key, curve[, inputEncoding[, outputEncoding[, format]]])。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
