bitchan / eccrypto

JavaScript Elliptic curve cryptography library
Creative Commons Zero v1.0 Universal
302 stars 98 forks source link

Any advice on how to encrypt the private key with a passphrase? #55

Open eddiejibson opened 4 years ago

eddiejibson commented 4 years ago

Hi,

I'm building an application that requires a private key to be encrypted/decrypted with a passphrase. As this is not currently a feature, what advice would you give me regarding how I should go about this? Planning on obviously pushing any changes I make privately to enhance this.

Thanks

JBaczuk commented 4 years ago

I would not recommend doing this as a passphrase is a weak key for encryption. Theoretically, you would take the passphrase and hash it into 32 bytes using something like sha256. Then you have to check and hope that it is a valid private key on the secp256k1 curve using isValidPrivateKey.

I would recommend looking at BIP39 Seed Phrases, that way it's not human generated, but still human readable.