Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

keyFromPrivate(privateKey).getPublic('hex') isn't returning the same public key as what I'm being shown by genKeyPair() #276

Open
joelwright-dev opened this issue Apr 4, 2022 · 2 comments

Comments

@joelwright-dev
Copy link

Hello all,

I'm writing a basic program to get the public key from a private key using this code:

return ec.keyFromPrivate(privateKey).getPublic('hex')

Where the privateKey is: 88575082256327777067088293295661531980671099272597078688043162004071352566123

To my knowledge, inputting this to the keyFromPrivate and getting the public key from it should give me the same value as the public key given to me in the genKeyPair() function which is: 040c395a32ce951496ff2610e57d50319d388744b84d02a0b407f3634691903252307ec63939cbd2b391545411e90c79feedece1b621150665480ea10416aa2e4f

However, this code returns a different key: 0459a50ae3c8c4015aa867d5a667b1cd7767100b66378a700df15de01e44ca509be402e8e2b8280538349844f94fc1c5f34d61b70717380cfd797d83975a5f957d

If anyone could help that would be greatly appreciated.

@fanatid
Copy link
Contributor

fanatid commented Apr 5, 2022

Please provide code for reproducing.

@webmasterinvizzo
Copy link

webmasterinvizzo commented Apr 12, 2023

try this test

const publicKey  = this.keyPair.getPublic().encode('hex');
const privateKey = this.keyPair.getPrivate('hex');
this.logger.error('keyPair::publicKey::', publicKey);
this.logger.error('keyPair::privateKey::', privateKey);

this.logger.warn("testKeys::recoveringValues");

const recKeyPar = ec.keyFromPrivate(privateKey,'hex');
const recPublicKey  = recKeyPar.getPublic().encode('hex');
const recPrivateKey = recKeyPar.getPrivate('hex');

this.logger.error('rec::publicKey::', recPublicKey);
this.logger.error('rec::privateKey::', recPrivateKey);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants