My goal is to encrypt some strings and store them in a database.
I am using RSA OAEP in Go (Golang):
rsa.EncryptOAEP(sha256.New(), rng, rsaPublickey, plaintext, nil) rsa.DecryptOAEP(sha256.New(), rng, rsaPrivatekey, ciphertext, nil)
I generated a public/private key pair with 4096 bits.
My understanding of RSA is very basic. I read some similar questions on stack overflow that say that RSA OAEP adds padding to ensure that a different ciphertext is generated for the same plaintext for security purposes.
I am more confident with using AES because if you supply the same symmetric key and the same initialization vector you will always get the same ciphertext.
P.S: I understand that RSA and AES have different use cases when it comes to sending data over the network and I should not treat them the same, but for my personal use case I want to use them for encryption/decryption of strings.
- Since different ciphertexts are generated for the same plaintext, is there a guarantee that I will be able to decrypt these RSA OAEP ciphertexts in the future ?
Implementations change, new libraries, functions & new versions of programming language runtimes are used, etc.
I am indifferent to the RSA OAEP implementation that will be used for decryption (Go, Java, Python, openssl, ...) as long as I can get the plaintext from the ciphertext.
The Go documentation says
Encryption and decryption of a given message must use the same hash function. In my case this hash function is SHA256.
Additionally the Go documentation says
The random parameter is used as a source of entropy to ensure that encrypting the same message twice doesn't result in the same ciphertext.
I haven't seen this random parameter (rng in my case) used in other programming languages. It seems to be specific to the Go RSA OAEP implementation.
So if I use an RSA OAEP decryption implementation with the same:
- Private key
- Hash function
I should be able to get the plaintext from all the encrypted strings. From what I see these 2 things seem to be the only requirements needed for decryption. Is this correct ? The answer is probably yes, but if possible, it would be nice to receive some more information about this to increase my confidence.