Q: How do I use OpenSSL to encrypt files?

A: This depends on if you want symmetric or asymmetric encryption.

For symmetic encryption, you can use the following…

To encrypt:

> openssl aes-256-cbc -salt -a -e -in plaintext.txt -out encrypted.txt

To decrypt this, you can use the following.

> openssl aes-256-cbc -salt -a -d -in encrypted.txt -out plaintext.txt

Now, for Asymmetric encryption you must first generate your private key and extract the public key.

> openssl genrsa -des3 -out private.key 4096
> openssl -in private.key -pubout -out public.key

To encrypt:

> openssl rsautl -encrypt -pubin -inkey public.key -in plaintext.txt -out encrypted.txt

To decrypt:

> openssl rsautl -decrypt -inkey private.key -in encrypted.txt -out plaintext.txt
This entry was posted in Answers, DragonFlyBSD, FreeBSD, NetBSD, OpenBSD, Security. Bookmark the permalink.

6 Responses to Q: How do I use OpenSSL to encrypt files?

  1. What's up says:

    It is hard to see the whole command-line and it requires scrolling ;(

    Please make it go away!

  2. Pingback: openssl file encryption « Morgen Free's Blog

  3. Pingback: encrypted files

  4. Roland Illig says:

    Unfortunately, the rsautl command lines only work for very small files. For larger files I get this error:

    4052:error:0406D06E:rsa routines:RSA_padding_add_PKCS1_type_2:data too large for key size:rsa_pk1.c:151

    See http://blog.altudov.com/2010/09/27/using-openssl-for-asymmetric-encryption-of-backups/ for an alternative.

  5. Pingback: zean.no-ip.info » How do I use OpenSSL to encrypt files?

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>