DEV Community

Michael Wahl
Michael Wahl

Posted on

1 1

Encrypting a file, using aes-256 and OpenSSL

Problem or Issue:

The other day I had a request to share and provide some sensitive information for some personal work I was going. The person requesting the information didn't have a secure drop-off or transfer method, and simply asked that I share via email.

Solution:

I am using a Mac, and will simply use a terminal with OpenSSL, but if you run Windows thats ok too and the same command should work, just change the in and out path to match your folders and file names.

For this short example, I created a short and simple test file named testfile.txt, which I will be using below.

To Encrypt the file, I simply issue the command below in my terminal

openssl enc -e -aes-256-cbc -a -in testfile.txt > testfile-enc123 -k ThisIsMySuperSecretPassword12345$.

To decypt the file and read the contents, I simply issue this command in my terminal

openssl enc -d -aes-256-cbc -a -in testfile-enc123 -k ThisIsMySuperSecretPassword12345$.

For this example all went well and I was able to read the contents of my file which simply says "Hello There 2022."

AWS Security LIVE!

Tune in for AWS Security LIVE!

Join AWS Security LIVE! for expert insights and actionable tips to protect your organization and keep security teams prepared.

Learn More

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs