search
HomeSystem TutorialLINUXHow to use OpenSSL to encrypt and decrypt files

How to use OpenSSL to encrypt and decrypt files

Jun 20, 2024 am 08:40 AM
linuxlinux tutorialRed Hatlinux systemlinux commandlinux certificationred hat linuxlinux video

如何运用OpenSSL 对文件进行加密和解密

OpenSSL uses cryptographic methods to encrypt or decrypt files

1. Use openssl to encrypt a file (data.zip is the original file, back.zip is the encrypted file)

# openssl enc -e -aes256 -in data.zip -out back.zip

Explanation: enc means symmetric encryption or decryption of files, -e means encryption of a file, -aes256 means encryption using the aes256 algorithm, -in means the file that needs to be encrypted, -out means the file generated after encryption new file. During the encryption process, you will be asked to enter an encryption password. Enter it twice to complete the encryption of the file

2. Use openssl to decrypt a file (back.zip is the encrypted file, data.zip is the decrypted file)

# openssl enc -d -aes256 -in back.zip -out data.zip

Explanation: enc means symmetric encryption or decryption of the file, -d means decryption of the file, -aes256 means decryption using the aes256 algorithm, -in means the file that needs to be decrypted, -out means the new file generated after decryption file, when decrypting a file, you will be asked to enter the password set when encrypting the file to decrypt it.

OpenSSL uses key mode to encrypt or decrypt files

1. First you need to use openssl to generate a 2048-bit key rsa.key file (rsa.key key file contains the private key and public key)

# openssl genrsa -out rsa.key 2048

2. Then extract the public key pub.key

from the rsa.key key file
# openssl rsa -in rsa.key -pubout -out pub.key

3. Use the pub.key public key to encrypt a file (data.zip is the original file, back.zip is the encrypted file)

# openssl rsautl -encrypt -inkey pub.key -pubin -in data.zip -out back.zip

4. Use the rsa.key private key to decrypt a file (back.zip is the encrypted file, data.zip is the decrypted file)

# openssl rsautl -decrypt -inkey rsa.key -in back.zip -out data.zip

Finally, we use the OpenSSL tool to encrypt and store all backup data files to ensure that the business system data is protected and leaked. We can also use other encryption tools such as GPG, VeraCrypt, and trueCrypt to encrypt data, but in comparison, using OpenSSL is more convenient because almost every Linux distribution comes with the OpenSSL software package pre-installed.

The above is the detailed content of How to use OpenSSL to encrypt and decrypt files. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
5 Best Free PDF to Word Doc Converters for Linux5 Best Free PDF to Word Doc Converters for LinuxMay 16, 2025 am 10:00 AM

Portable Document Format (PDF) remains a widely used file format due to its consistent standards across different platforms and devices, compatibility, and compact size.Numerous powerful tools are available for viewing PDF files, catering to various

How to Install Linux Mint 22 Mate on Your ComputerHow to Install Linux Mint 22 Mate on Your ComputerMay 16, 2025 am 09:44 AM

Linux Mint 22, codenamed “Wilma”, was officially launched as a significant update to Linux Mint on July 25, 2024. Linux Mint 22 is an LTS (Long Term Service) release, built upon Ubuntu 24.04, and will receive support until April 2029.As anticipated,

How to Hack Your Own Linux System to Strengthen SecurityHow to Hack Your Own Linux System to Strengthen SecurityMay 16, 2025 am 09:39 AM

Passwords serve as the primary security measure across various systems, including Linux, where the root password grants full control over the system. They are essential for securing BIOS, login, disks, applications, and more.Linux is widely regarded

6 Best Linux Software and Apps with Data Encryption6 Best Linux Software and Apps with Data EncryptionMay 16, 2025 am 09:33 AM

Data encryption is an essential component of modern cybersecurity, enabling the encoding of data to render it unreadable to unauthorized users. To enhance your online security, consider choosing software that incorporates this vital feature as a stan

How to Install Linux Mint 22 XFCE on Your ComputerHow to Install Linux Mint 22 XFCE on Your ComputerMay 16, 2025 am 09:28 AM

Linux Mint 22, with the codename “Wilma”, has been officially launched and is ready for download. Built on Ubuntu 24.04, it offers support until 2029 and comes in three flavors: Cinnamon, MATE, and XFCE.This guide will take you through the steps to i

16 Best Open Source Cloud Storage Software for Linux in 202416 Best Open Source Cloud Storage Software for Linux in 2024May 16, 2025 am 09:15 AM

The term "cloud" evokes a sense of vastness and expansiveness. In the technology sector, "the cloud" denotes a virtual platform that delivers services to end-users, encompassing data storage, application hosting, and the virtualiz

How to Install Linux Mint 22 Cinnamon on Your ComputerHow to Install Linux Mint 22 Cinnamon on Your ComputerMay 16, 2025 am 09:10 AM

Linux Mint is a contemporary, user-friendly, and community-driven GNU/Linux desktop distribution, built on the well-known Ubuntu Linux distribution. It's an excellent choice for users transitioning from Windows or macOS to the Linux environment.Linux

4 Best Tools to Create PDF Forms on Linux4 Best Tools to Create PDF Forms on LinuxMay 16, 2025 am 09:08 AM

Introduction: In this article, you will find the best applications for creating PDF files (also known as interactive tables) on Linux. If you need powerful tools to create and edit PDF files on Linux, you have many applications to choose from. These applications are able to perform basic editing operations such as merging pages, cropping pages, adding comments, and sometimes even providing advanced features. However, not all PDF editors can create PDF forms—that is, editable PDF files with interactive fields that can be filled in by other users. Such documents are useful in situations like you need to create a questionnaire, an admission form, or a sales contract, etc. The following list includes solutions that can run on various Linux distributions,

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.