I'm writing a file server that encrypts data on the client side, sends the data over TCP, and decrypts it on server side using asymmetric RSA-OAEP encryption. There are two main functions I have been trying to use, which take the following arguments per the documentation:
EncryptOAEP(hash hash.Hash, random io.Reader, pub *PublicKey, msg []byte, label []byte) (out []byte, err error)
DecryptOAEP(hash hash.Hash, random io.Reader, priv *PrivateKey, ciphertext []byte, label []byte) (msg []byte, err error)
Each requires a random io.Reader
, and the test file uses rand.Reader
from crypto/rand. However, whenever I encrypt a message with rand.Reader
on the client side, the message never is decrypted properly on the server side which has a separate instance of rand.Reader
.
- What is the purpose of the
random io.Reader
? - How can I ensure that the encrypted message is transferred and decrypted properly by the server? Would I also need to transfer some information about the
rand.Reader
used by the client as well to the server for the message to be properly decrypted?