How to encrypt a file with RSA and AES-256 that anyone with RSA key can decrypt them?.

  • If you want to encrypt a file so that someone else can read it, you give them the key. – squeamish ossifrage Nov 2 at 14:54
  • 1
    Well come to Crypto.StackExchange . Please post your question well-formated and well described. Public key algorithm ( like RSA), in general, are used to key exchange or signatures whereas private key algorithms are used to encryption. So, what is your aim? – kelalaka Nov 2 at 14:55
  • gpg would work (this uses RSA keys by default and can use AES-256 if so configured); anyone with the private RSA key can decrypt. – Henno Brandsma Nov 2 at 15:47
up vote 3 down vote accepted

Another name for hybrid crypto is envelope encryption. If you have a file you want to encrypt, you choose a random value to use as an AES key, encrypt the file using AES and that key, then encrypt the AES key using the RSA public key of each user to whom you want to grant access to the encrypted file.

Note that this is pretty much what GPG does if you encrypt a file to a list of public keys. The algorithms might not be AES and RSA, but they will be a symmetric encryption algorithm to actually encrypt the file, then an asymmetric encryption algorithm to encrypt the symmetric key to each public key.

It sounds like you're looking for a hybrid crypto solution. Some libraries provide APIs for this, e.g. libsodium. Others, you have to build it yourself with the RSA and AES primitives provided, e.g. OpenSSL.

Without more information from you on your environment (e.g. programming language) it's really hard to provide any specific help.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.