0
$\begingroup$

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.

$\endgroup$
12
  • 2
    $\begingroup$ With $10$ digits, you can write $10^{10}$ different integers. With $64$ bits, you can write $2^{64} \approx 10^{19.3}$ integers. So I am sorry to say that you cannot compress the key without losing information on it (and therefore losing the key). However, if you allow characters other than digits (such as Base 64), then you can write it in a few characters. $\endgroup$
    – user69015
    Commented Jun 19, 2020 at 12:41
  • 1
    $\begingroup$ Welcome to Cryptography. A similar question has been asked within last week. First of all, This is just encoding. secondly, In real life, RSA keys are >2048 -bits and whether you transfer as in the link or not, not easy to remember... $\endgroup$
    – kelalaka
    Commented Jun 19, 2020 at 12:44
  • $\begingroup$ @corpsfini I can change the length of integer to whatever I want 64 was just an example If you can help me in reducing an integer I would be glad to know it. Lets connect out of Cryptography as I am new to it and restricted to most of the stuff $\endgroup$
    – Ritvik
    Commented Jun 19, 2020 at 12:50
  • $\begingroup$ @kelalaka Helllo and thankyou. I understood that it has 2048 but I am using RSA on personal level for encrypting a database file. I found that 2048 will be more than enough and might not be required although I am quite flexible to generate any length of key til I can some how reduce or compress it to a 10 digit or less integer or number for a person to remember. $\endgroup$
    – Ritvik
    Commented Jun 19, 2020 at 12:53
  • $\begingroup$ @kelalaka comming back from the suggested post. The there asks to map the key over a database of words to make a phrase that i also thought of but during the though process only I got more than 2 flaws in the approach and I dropped it. I am not really good at maths for cryptography but I do remember solving question in high school for sum of factorials of digits of a number (23 => 2!+3!+4! = 8) . I want something like this we have a faster and easy recovery algo also. $\endgroup$
    – Ritvik
    Commented Jun 19, 2020 at 12:57

1 Answer 1

2
$\begingroup$

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.

$\endgroup$
3
  • $\begingroup$ thanks @fgrieu for telling me the flaw and solution. I will surely be looking into both the solutions 1 and 2. $\endgroup$
    – Ritvik
    Commented Jun 19, 2020 at 15:07
  • $\begingroup$ Does 10 digit is enough passwords size? $\endgroup$
    – kelalaka
    Commented Jun 19, 2020 at 17:49
  • 1
    $\begingroup$ @kelalaka: with 2 seconds of Argon2 or scrypt, 10 digits give some level of security. We are talking an expected 1 years of use of 317 instances of the equivalent hardware: $10^{10}/86400/365\approx317$ $\endgroup$
    – fgrieu
    Commented Jun 19, 2020 at 19:13

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.