I found this statement
In RSA crypto, when you generate a key pair, it's completely arbitrary which one you choose to be the public key, and which is the private key. If you encrypt with one, you can decrypt with the other - it works in both directions.
in this question from StackOverflow. I would like to prove myself that this statement is true by actually trying it myself.
I have GnuPG 1.4.16 installed on my linux. I made two keys in pubring:
/home/alex/.gnupg/pubring.gpg
-----------------------------
pub 2048R/0FDEC709 2017-08-11
uid alice <alice@mail.com>
sub 2048R/8B76560E 2017-08-11
pub 2048R/E500C1B1 2017-08-11
uid bob__ <bob@mail.com>
sub 2048R/B9D82FDE 2017-08-11
If I want Alice to send message to Bob I encrypt message like so:
gpg --output message.encrypted --encrypt --recipient bob@mail.com message.plaintext
If I want Bob to decrypt message received from Alice using his private key I type:
gpg --output message.decrypted --decrypt message.encrypted
after which Bob is prompted for passphrase and if it's correct message is decrepted.
Here, I assume gpg
handles selecting Bob's public key when encrypting and using Bob's private key for decrypting, because I don't spesify that information myself. (If I am wrong with my assumptions/understanding of how gpg
works - please let me know, I am new to it).
Now, I want Alice to send message to Bob again, but this time I want to use Alice's private key to encrypt, and then I want Bob to use Alice's public key to decrypt.
Question(s)
- What commands or what parameters should I pass to
gpg
to achieve that? - Can GnuPG even allow me to do this? Should I use some other program?
Note: I am not trying to --sign
that message. I am trying to prove to myself whether quote at the top of question is true or false, and that quote says nothing about signing.
A little bit of background of how I got here
I was trying to understand how RSA/public key/private key "stuff" works. I discovered that there is misunderstanding going on in this area in community. A lot of people say "signing is the same as encrypting with private key". I do not know how RSA internally implement things, and reading and understanding this will take me months, if not years, probably. Nevertheless, after reading this, this, this, this, this, this, this I find answers like this, this, this, this confusing. So far everywhere I looked I only saw people talking, but haven't seen somebody provide concrete example. If this is duplicate - let me know, I will remove this question. Also, I might be asking the wrong question, but I am here to find out.
Edit 1
Using this website you can generate public and private keys and try to encrypt/decrypt some message. If you do it the proper way (encrypt with public, decrypt with private) it works. But if you do it the other way around - it does not work. Which means a few things to me:
it's a bug in javascript library
quote at the beginning of this question is false
there is some
if
statement in javascript library that says something like (it's a "jQuery pseudocode", hopefully you know what I mean)if($('#privatekey').value.contains('public') { return false; }
which is meant to restrict people like me from even trying to decrypt messages with public keys.
it's non-intentional bug not in library itself, but in how it was used
Any other reasons?
But I am not worried too much about this website not doing it. I was looking into established program (or even just library) that can achieve what I was describing.
The javascript library used in that website appears to be kbpgp.
Notes
I did diff of encryption and decryption primitives vs signature and verification primitives from this text. Here is a link to diff. It appears that they are a "mirror image" of one another. What message
in encryption is what signature
in verification, and what ciphertext
in decryption
is what message
in signing
. As I understood that is what being called Raw RSA in this answer. But another thing this answer also states is that
It is often mentioned that signing is equivalent to RSA encrypting (the hash over) the message using the private key. This is only true if you disregard the required padding mechanism. The RSA padding mechanisms are different for encryption and signing.
By taking a quick look at padding (which is described in chapter 7 for encryption and chapter 9 for signing), description of padding indeed looks different for both encryption and signing (but I want to/have to look more into it). Which kind of narrows down my question to finding out whether padding implementation of encryption (aka. RSAES-OAEP
or RSAES-PKCS1-v1_5
) will allow me to encrypt with private key, and decrypt with public key safely, producing original message.