Skip to content

ecdh.setPublicKey is actually useful and should be undeprecated #18977

Description

@skerit

So ecdh.setPublicKey has been deprecated since v5.2.0, but there is a certain use case where it is very useful: when you need to uncompress a compressed public key.

Here's how I would uncompress such a public key:

constcrypto=require('crypto');letecdh=crypto.createECDH('secp256k1');ecdh.generateKeys();letprivate_key_compressed=ecdh.getPrivateKey(null,'compressed');letpublic_key_compressed=ecdh.getPublicKey(null,'compressed');// Public key is a buffer of 33 bytesconsole.log('Compressed public key:',public_key_compressed.length,public_key_compressed);// Create a new ecdh objectecdh=crypto.createECDH('secp256k1')// Use the compressed public key to set the public keyecdh.setPublicKey(public_key_compressed);// Get the uncompressed getletpublic_key_uncompressed=ecdh.getPublicKey();// The returned key is a buffer of 66 bytes longconsole.log('Uncomrpessed public key:',public_key_uncompressed.length,public_key_uncompressed);

If ecdh.setPublicKey where to disappear I would require another library just for this simple task.

Metadata

Metadata

Assignees

No one assigned

    Labels

    c++Issues and PRs that require attention from people who are familiar with C++.cryptoIssues and PRs related to the crypto subsystem.feature requestIssues that request new features to be added to Node.js.good first issueIssues that are suitable for first-time contributors.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions