I need a reproducible way to generate the same password from an RSA private key and should not depend on the OpenSSL version and other thing that like a file format...



openssl dgst -sha256 -sign private.key -out signature /dev/null

I would like to know if the signature file will stay exactly the same (at the nearest octet) if I retry this command in the future?


In fact I have a PKI which generate one key for each system used for the secure boot to sign the EFI image (EFI stub + kernel + initrd). The system need to have the hand on the private key to regenerate the EFI image for each kernel upgrade. The private key is stored on the LUKS encrypted rootfs, un locked on the boot with the TPM.

The need: I would like to produce a 512bits long key, derived from the RSA key and stored on a LUKS slot, to be able to unlock my encrypted container with in additional to the TPM one.

With this, I can recover an encrypted disk from a crashed system, using the corresponded RSA private key from the PKI database.

  • 2
    OK, this question, together with the comments under bs-'s answer, really sound like you're doing something unwise, cryptographically/security-wise. Please explain why you want to do this. You, in general, would never give out information about a private key. Never. You'd even avoid carrying out in any form any verifiable identifier of that private key, aside from the public key. And: the private key is the private key. That doesn't change over time. The container format for it might change, but the actual bits of the key stay the same, so I'm not sure where any problem ever arises from. Feb 17, 2023 at 14:39
  • @MarcusMüller I had added some details on the context Feb 17, 2023 at 15:17
  • @MarcusMüller I need the OpenSSL command to extract the actual bits of the key and generate a unique and reproducible signature. Feb 17, 2023 at 15:21
  • Thanks! So it's not a password, but a LUKS recovery key! So, if that's the case and you have an orderly database, why does the recovery key need to be derived from the private key? Can't it just be random? Feb 17, 2023 at 15:37
  • Btw, just encrypting some data with the private key would go as signature. Feb 17, 2023 at 15:38

1 Answer 1


Applying a cryptographic hash function to the RSA private key is a reproducible way to generate a password from the key.

The key cannot be recovered from the hash due to the properties of cryptographic hash functions.

Whether this approach is desirable will depend on the broader context.

  • Welcome to U&L. You need to add more explainations.
    – GAD3R
    Feb 17, 2023 at 12:51
  • @GAD3R I'd love too, but the question is rather vague.
    – bs-
    Feb 17, 2023 at 12:54
  • Yes, I had thinking about it, but the problem is to ensure to have the key in raw format from the PEM format and be ensured that I have the same result in the future with the same PEM key and another version of OpenSSL. Feb 17, 2023 at 12:56
  • To avoid flagging your answer as very quality.
    – GAD3R
    Feb 17, 2023 at 12:56
  • 2
    @GAD3R not sure what you're getting at, the answer is accurate, on point and there's nothing it leaves unclear. Feb 17, 2023 at 14:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .