简体   繁体   中英

Generate Private key from seed

Is there any way to generate a private key and public key from a string like a user's password? I want to retrieve it every time the user enters password

I use this elliptic but it randomly generates a keyPair

const EC = require('elliptic').ec;
const ec = new EC('secp256k1');
let keyPair = ec.genKeyPair();

Disclaimer : Don't create brain wallets: especially low entropy human generated ones.

You can generate any 32-byte value (technically valid private keys on secp256k1 curve must be between 0x1 to 0xFFFF FFFF FFFF FFFF FFFF FFFF FFFF FFFE BAAE DCE6 AF48 A03B BFD2 5E8C D036 4140 ) see Bitcoin Wiki

One way to do this is to hash the string you want to generate the key from:

const EC = require('elliptic').ec;
var crypto = require('crypto');

const ec = new EC('secp256k1');
let secret = crypto.createHash('sha256').update('password').digest('hex');
let keyPair = ec.keyFromSecret(secret);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM