Generate a keypair from a password

后端 未结 2 1201
粉色の甜心
粉色の甜心 2021-01-25 10:44

I would like to use asymmetric encryption based with a private key based on a password. The requirement is the security level provided must be the same of (1) using password-bas

相关标签:
2条回答
  • 2021-01-25 11:18

    If you base the private key solely on a password, it will only be as strong as the password, i.e. whoever can guess the password can get the private key.

    This is comparable to generating a private/public key pair, encrypting the private key with a symmetric cipher and then publishing both together.

    This of course makes the whole system weaker, since you no longer need to have the secret token - you only need to know the password.

    0 讨论(0)
  • 2021-01-25 11:25

    Every time I see this question or a variant of it asked it's usually the result of bad design decisions. Almost always, the correct answer is to generate a random RSA keypair and protect the private key using standard password-based encryption like PBKDF2 or argon2. I've only seen one use case where this made at least a little sense and that was a cryptographic token back in the day with absolutely no nonvolatile storage. You won't find it around because there's no reason to build such a token, nonvolatile storage is not exotic in 2018.

    In general you can do this: java's RSA key generation code accepts an instance of SecureRandom which the Oracle providers use to generate the candidate primes for RSA. You can subclass SecureRandom (I think) to provide a class that uses the password to seed a deterministic, repeatable sequence of random numbers such that every time you call KeyPairGenerator. generateKeyPair() the same keypair (including the private key) is generated. The bouncycastle library includes an example, FixedSecureRandom, that can be used as a model. Note that the deterministic RNG still has to be cryptographically secure, apart from the fact that it will not have enough entropy. FixedSecureRandom is not secure, it simply returns the pre-supplied bytes directly as output. Perhaps you can merge FixedSecureRandom with one of the other CSPRNGs in the org.bouncycastle.crypto.prng package.

    0 讨论(0)
提交回复
热议问题