In Openssl, is there a way to systematically generate a private key such that every time you perform this key derivation, you produce the same private key?

It seems like every openssl command that generates private keys does so randomly. So, if you lose your private key file for whatever reason, there's no practical method of recovering it. I know you can control some parameters of RSA key generation like the size and the exponent, but what if you wanted a specific modulus that you could remember?

Likewise, for ECDSA if you know a private key that is valid for a particular curve type,

  • How would you generate the public key from that chosen private key?
  • Maybe there is a way to edit a PKCS1/8 file so that you can change the private key?
  • Or, maybe there is an option for genrsa/gendsa/genpkey/etc that allows you to derive the private key from a passphrase?
  • 1
    $\begingroup$ I see the problem - the private key PEM file contains an uncompressed public key which bloats the length of the file, which means there is an unnecessary amount of information that would need to be written down. These answers say you can't do it with OpenSSL, but you can specify a seed with GnuTLS $\endgroup$
    – knaccc
    Apr 12, 2023 at 20:50

1 Answer 1


For RSA, because the key is highly structured, no.

For ECDSA/ECDH you can just use a costly hash like scrypt or argon2 of whatever, truncated if necessary, as privatekey and openssl can derive the publickey -- see https://stackoverflow.com/questions/48101258/ (commandline) or https://stackoverflow.com/questions/75474348/ (library). For EdDSA/XDH and DSA (in a known group, which doesn't need to be secret) you don't even need that; PKCS8 format only needs the privatekey number (which for XDH must be munged slightly to ensure it's not in a small subgroup and the multiplication can't be shortcutted creating a sidechannel).

But any key you can remember, or derived from something you can remember, is very likely breakable -- some Bitcoin users tried this and most lost their money; google brainwallet. (Although this happened back when Bitcoin was only a few hundred dollars, so they didn't feel quite as much agony as they would have last year, and maybe yet this year it will bounce back, who knows.)


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.