0

Situation:-

I am using Python. I am using RSA and I am using two 64 bit keys. I am not an cryptographer . I can provide you the RSA code if needed but i am not posting it as it doesn't have to do anything with the problem. I have to give the private key to a human to remember well 64bit key cannot be remembered by normal humans as far as know.

Problem: -

I want a method to compress my 64bit key to at least an integer of 10 digits and a method when those 10 digits are entered they decompress back to 64bit key.

Solution I have tried: -

Converting my 64 digit integer sequence to an string phrase or a string (the worst Idea wasted a lot of time do not try yourself).

Using basic math operations such as 'division', 'subtraction', etc. This proved to be not a good practice as it is easily readable in the code.

Note

I need not to change the private key whenever programs run but whenever client wishes to.

Ritvik
  • 3
  • 2

1 Answers1

2

If is not possible to reversibly compress a 64-bit RSA key (nor a 64-bit prime) into 10 digits after the fact: there are just too many such keys or primes to assign them a unique 10-digit value. And at this size RSA is totally insecure, I mean breakable in a fraction of a second. Even 640-bit is insecure, see history or factorization records there.

However, that are several ways to use secure parameters for RSA and arrange things such that what's needed to decipher can be remembered as 10 digits (or a short passphrase or sequence of words: that's easier for most humans).

  1. The classical way, used e.g. in PGP/GPG and OpenSSL, is to use a normal RSA key (say, 4096-bit) and encipher it when at rest using password-based encryption, with the 10-digit value used as the passphrase/password. That is symmetric cryptography, with the symmetric key derived from the password (and salt) by a purposely slow hash function, such as Argon2, scrypt
    When the private key is needed, the passphrase-to-key slow hash is run, recovering the symmetric key, then used to decipher the RSA private key (stored in a file, but here that could be in the database). The public key is stored in clear (it's not secret anyway).

  2. A less common option is to generate the primes in the RSA key using a Cryptographically Secure Pseudo-Random Number Generator (CSPRNG) seeded by a key derived as above. When the private key is needed, the passphrase-to-key slow hash is run, recovering the symmetric key, then used to seed the CSPRNG and re-generate the same RSA private key as originally.

The advantage of 2 is that it's impossible to loose the encrypted version of the private key, since none is needed. It's drawback is that it is impossible to change the passphrase, and that we loose the first line of defense against attacks: we normally try to keep the encrypted private key out of reach of attackers.

fgrieu
  • 149,326
  • 13
  • 324
  • 622