Dotlayer
  • News
  • Startups
  • Tutorials
  • SEO
  • Marketing
  • Interviews
No Result
View All Result
Dotlayer
  • News
  • Startups
  • Tutorials
  • SEO
  • Marketing
  • Interviews
No Result
View All Result
Dotlayer
No Result
View All Result

How to Encrypt & Decrypt Files with OpenSSL on Ubuntu and Mac OS X

November 28, 2018
in Tutorials
0 0
Share on FacebookShare on Twitter

OpenSSL is an open source library that provides a full-featured toolkit and APIs for secure computer network communication over Transport Layer Security (TLS) and Secure Sockets Layer (SSL) protocols on Linux and other Unix-like systems

The source code of the project lives on GitHub and is managed by a worldwide community of software engineering volunteers with over 300 contributors.

Most network communication apps, personal computers, web servers, cell phone and tools that use TLS/SSL protocols have a version of OpenSSL installed on them.

The default toolkit of OpenSSL that comes with Ubuntu isn’t the latest. To get the latest, you must download it yourself and install. An older version will work with the tutorial as well. You do not need to upgrade to follow this tutorial.

Just as mentioned in the title, in this tutorial we will be using OpenSSL in a slightly unusual way, we will be using it to encrypt and decrypt a file on our computer.

Since OpenSSL allows us to specify the encryption algorithm to use, we’ll use the des3 encryption algorithm, which in simple terms means a complex encryption algorithm is applied three times to each data block, making it difficult to crack through brute force methods or other computer hacking methods.

While we will be focusing on Mac OS X and Ubuntu in this article, these commands will work anywhere that OpenSSL is installed, including older versions of OS X, CentOS, and all other Linux variants.

How to install OpenSSL on a Ubuntu

Most versions of Ubuntu come with OpenSSL installed, it is usually not the latest version but just as mentioned above it you can use it for this tutorial. If you want to verify which version of OpenSSL you have installed, you can do that easily by typing the command below in your terminal.

openssl version -a

This should display all information related to the version of OpenSSL you have installed on your computer, it should be similar to the output below:

LibreSSL 2.2.7
built on: date not available
platform: information not available
options:  bn(64,64) rc4(ptr,int) des(idx,cisc,16,int) blowfish(idx)
compiler: information not available
OPENSSLDIR: "/private/etc/ssl"

If you don’t have it installed, you can just use the commands below to install it and all it’s associated development libraries.

sudo apt-get install libssl-dev
sudo apt-get install openssl

How to install OpenSSL on a Mac

To install OpenSSL on a Mac we will be using homebrew. By running the commands below you will have OpenSSL installed and linked correctly on a Mac

    brew install openssl
    brew link --force openssl

How to Encrypt Files with OpenSSL

With OpenSSL installed and verified on our system, we can so ahead and use it to encrypt and decrypt individual files.

The syntax for using OpenSSL is pretty basic: It starts with the command
openssl and you specify the type of encryption, and then you add the file that needs to be encrypted. Below is a template of the command used.

openssl [encryption type] -in [file to encrypt]

We’ll be using the des3 encryption algorithm for this example, and we’ll be using a text file as the input. We’re also going to specify a different output file to prevent any errors.

Here is what the command would look like:
des3 which is short for Triple Data Encryption Standard (DES) is a type of computerized cryptography where block cipher algorithms are applied three times to each data block.

openssl des3 -in file.txt -out encrypted.txt

You will be asked to set and confirm a password before the encryption is complete, do not lose this password or you will lose access to the file.

Additionally, you can also just use an input file within filename, but that may cause issues. To prevent any unexpected problems, do not specify the same file as the input and output. This means the original file will stick around either before or after encryption, and you will want to deal with that file individually, preferably through a secure delete method.

Decrypting Files with OpenSSL

openssl des3 -d -in encrypted.txt -out normal.txt

In the previous section, we set password will be required to decrypt the file. Once you execute the command above, you will be asked for the password you used. Other than switching the placement of the input and output, where again the original file stays put, the main difference here is the -d flag which tells OpenSSL to decrypt the file.

If you are wondering what happens when the password is invalid, you’ll get an error message, but if you force open the file with something like TextEdit, you’ll see the text encrypted version followed by a bunch of gibberish like so:

The file will remain unreadable until it has been decrypted through OpenSSL again. For more about file security follow us on Twitter, Facebook and sign up for our newsletter.

ShareTweetPin
Previous Post

How to Use an Ansible Playbook To Install WordPress on Ubuntu 18.04 and 16.04

Next Post

Guide to the Five Best Video Marketing Trends in 2019

Next Post

Guide to the Five Best Video Marketing Trends in 2019

You might also like

Calendarific Unveils New Pricing Plans

Calendarific Unveils New Pricing Plans

July 27, 2023
CurrencyBeacon vs. Currency Freaks, Fixer.io, and OpenExchangeRates: Which API is Best?

CurrencyBeacon vs. Currency Freaks, Fixer.io, and OpenExchangeRates: Which API is Best?

June 17, 2023
Mint Linux vs Ubuntu: Which is Right For You?

Mint Linux vs Ubuntu: Which is Right For You?

March 12, 2022
Net Neutrality: What is it and Why Should You Care?

Net Neutrality: What is it and Why Should You Care?

March 12, 2022
Solid State Drives – Why You Should Buy One Today

Solid State Drives – Why You Should Buy One Today

March 12, 2022

Machine Learning Algorithms Every Beginner Should Know

January 25, 2022
  • Terms of Service
  • Privacy Policy
  • Careers

© 2021 Dotlayer.com

No Result
View All Result
  • About Us
  • Advertise
  • Blog
  • Careers
  • Contact
  • Contact Us
  • Get Featured
  • Home Layout 1
  • Home Layout 2
  • Home Layout 3
  • Privacy Policy
  • Security
  • Services
  • Subscribe To Dotlayer
  • Terms of Service
  • Write For Us

© 2021 Dotlayer.com

Welcome Back!

Login to your account below

Forgotten Password?

Retrieve your password

Please enter your username or email address to reset your password.

Log In