Go: Should I use secretbox or RSA? I want to encrypt a file with a RSA public key.


I generate a random 16 bytes key
I encrypt the file with AES + the random key (aes.NewCipher() + cipher.NewGCM() + aesgcm.Seal())
I encrypt the random key with RSA (rsa.EncryptOAEP())


Now I can send the encrypted file + encrypted random key to the person who has the private RSA key.

I read that secretbox should be favored over the RSA package: should I keep using RSA? What is the difference with the secretbox package?
Do you need to grant someone the ability to encrypt messages whom you do not want to grant the ability to decrypt messages?  If so, you need public-key encryption—and you probably want public-key authenticated encryption.


For example, if you want to separate the ability to create archives from the ability to read archives at a later time, then you probably need public-key (authenticated) encryption, like Tarsnap.

Although you might be the only human in the system handling the archives, the machine that creates the archives—a virtual server hosted at Amazon constantly listening to the internet, say—might be meaningfully distinct from the machine that reads them—e.g., a laptop deployed only once, in an emergency, with a USB key stored under your mattress—and as such you might impose a meaningful privilege boundary between them.
Consider using NaCl box instead of building something yourself out of difficult parts like RSA with OAEP.

As a bonus, NaCl box is smaller than anything you build out of RSA, and decryption is much faster, and the code will be simpler, and you naturally get public-key authenticated encryption where it would take much more work to design a bespoke system with RSA.


Is the party that encrypts messages the same as the party that decrypts messages, with no meaningful privilege boundaries?  If so, then NaCl secretbox is fine.