1
$\begingroup$

Imagine you have RSA key pair. You also have some text data. So public key and text data are visible to everyone. Question is, if you sign the text_data with the private key, is the result considered as good secret? For example is it good idea to convert it to base64 string and use it as a password?

Real world problem is related to Android application development. I'm trying to generate strong password that is used as passphrase for local database. Of course I can't store the hard coded password string as plain text but maybe I could use Android KeyStore to generate RSA key pair and then use it to generate strong password.

$\endgroup$
2
  • $\begingroup$ Note that some algorithms produce a randomized signature, which would create problems using the signature as a key $\endgroup$ Sep 12, 2022 at 19:42
  • $\begingroup$ The standard RSA secure signature scheme is RSA-PSS and that uses different randomness for each sign operation. This means you need to modify it or use the RSA Textbook RSA signature. RSA with a private key is a good random permutation. $\endgroup$
    – kelalaka
    Sep 12, 2022 at 21:39

1 Answer 1

-1
$\begingroup$

RSA is a public-key cryptosystem. This means that you publish your public key in order for people to encrypt and you use your private key in order to decrypt.

When signing a message, you create extra information, meaning you don't change what you send, you just add a value. Then, the receiver can check that the signature is valid and "believe" that he/she didn't received the message from an imposter.

Answering your question, because you want to create a passphrase and not store the hard coded password as a plain text, signing doesn't work because you don't encrypt anything but rather just ensures that you (the one with the generated RSA pair key) have indeed stored that password.

What you probably want if I'm understanding correctly is hashing the password and store the hash as hard coded. So basically you can use a popular hash function like SHA-256 and hash your password. For example, the password "passphrase" is hashed as 1e089e3c5323ad80a90767bdd5907297b4138163f027097fd3bdbeab528d2d68.

The convenient thing about hash functions is that you can't go back, meaning given 1e089e3c5323ad80a90767bdd5907297b4138163f027097fd3bdbeab528d2d68, you can't find the word "passphrase". Another convenient thing is that it is "almost" always, collision free, meaning that no other word could produce the same hash. Lastly, "passphrasee" (an extra e) gives as a hash ea1c584e4a0e8aac0647a0cf91bb102113e633a0be24d8901135d2b501f6958f, a completely different hash. This way, you don't know if you are "near" of finding the original word.

So, you keep the hash, and each time a user tries to input the passphrase, you will hash it with the same hash function. If the output is the same as the hash you have stored, then you know the person knows the correct password. If the output isn't the same as the hash, then the user wrote an incorrect password. Even if someone looks the hard coded hash, he wouldn't be able to find the real passphrase.

$\endgroup$
4
  • $\begingroup$ In this case, i wouldn't have to store anything. I'd just use the private key provided by Android system and use it to sign the "passphrase". Then the result would be used as password for database. Then if I want to open the database, I just ask the private key again from the system and sign the "passphrase" again. I wouldn't even need public key for anything. Anyway, I dont know if it's cryptographically secure that way. $\endgroup$
    – nsko
    Sep 12, 2022 at 18:23
  • $\begingroup$ I don't understand what you mean by sign the "passphrase". Signing means by having the RSA pair, you will get the "passphrase", hash it and then raise it to the power of your secret key. This is a signature of your passphrase (based from Wikipedia textbook RSA). Probably what you mean is encrypt your password. Still, what exactly you mean? If you just want to encrypt things with a private key, there is no need for RSA, this is like one time pad. You have a secret key and you encrypt/decrypt with it. $\endgroup$
    – Alex Them
    Sep 12, 2022 at 20:13
  • 1
    $\begingroup$ meaning that no other word could produce the same hash. !!! Words are vulnerable to dictionary attack ( short input space problem ). If we move from words to sentences the first sentence is obviously wrong by the pigeon-hole principle $\endgroup$
    – kelalaka
    Sep 12, 2022 at 21:40
  • $\begingroup$ Maybe the question is, if it is possible to guess/derive the signature from the public key and "passphrase"? Assuming the private key is unexposed $\endgroup$
    – nsko
    Sep 13, 2022 at 8:31

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.