Encryption Commands & CLI Tools — OpenSSL, GPG, 7-Zip, Cryptsetup & More

Whether you are scripting automated backups, securing a server environment, or just prefer the granular control of the terminal, mastering CLI encryption is essential. This technical reference covers the exact commands needed to secure data across Windows, Linux, and macOS.

By the Editorial Team • Updated August 2026 • 12 min read
Quick Answer

To quickly encrypt a file using the industry standard AES-256 algorithm via OpenSSL, open your terminal and run:
openssl enc -aes-256-cbc -salt -in file.txt -out file.enc
You will be prompted to enter a password. To decrypt, add the -d flag.

Encryption concepts and secure data protection illustrated for a command-line encryption guide

Inside this guide

Developer Context: How Modern Encryption Algorithms Work

At the command line, you bypass user interfaces to interact directly with cryptographic libraries. Most tools reference here utilize Symmetric Encryption (like AES-256) or Asymmetric Encryption (like RSA/PGP).

When you run an openssl encrypt file command, the software takes your plaintext, derives a cryptographic key from your password (using a hashing algorithm and a "salt"), and scrambles the data block by block. A lock file or .enc output is generated, which appears as random noise to anyone without the key.

How encryption software transforms plaintext into protected encrypted data

What is the difference between AES-128 and AES-256 encryption?

AES (Advanced Encryption Standard) is a symmetric cipher. The number (128 or 256) refers to the key length in bits. AES-256 offers a much larger key space ($2^{256}$ possible combinations), making it mathematically impossible to brute-force with current computing power. For almost all CLI commands today, AES-256 is the default recommendation.

Scenario Selector

Select your situation below to jump to the right tool:

Single File Security

I need to quickly encrypt a specific file or document before sending it to a server.

→ Use OpenSSL
Secure Communication

I need to send an encrypted message or file to a specific person using public keys.

→ Use GPG / PGP
Hardware Security

I need to lock down an entire USB drive or partition via command line.

→ Use BitLocker CLI

OpenSSL Commands Reference

OpenSSL is the Swiss Army knife of cryptography. It is pre-installed on most Linux and macOS systems, and available for Windows.

Computer keyboard used for entering OpenSSL encryption commands in a terminal

openssl aes 256 encrypt (Symmetric Encryption)

To encrypt a file using AES-256 in Cipher Block Chaining (CBC) mode with a salt (highly recommended for security):

Bash
openssl enc -aes-256-cbc -salt -in sensitive_data.txt -out secure_data.enc

openssl decrypt file

To reverse the process, you use the exact same algorithm flag but add the -d (decrypt) switch:

Bash
openssl enc -d -aes-256-cbc -in secure_data.enc -out restored_data.txt

"aes-256-gcm" openssl enc

GCM (Galois/Counter Mode) provides both data confidentiality and authenticity (verifying the file hasn't been tampered with). It is considered superior to CBC for many modern applications:

Bash
openssl enc -aes-256-gcm -in file.txt -out file.enc -K [hex_key] -iv [hex_iv]

Note: GCM in OpenSSL's `enc` tool requires passing the Key and IV directly in hex, making it better suited for scripts than manual password entry.

GPG / PGP Commands & Key Management

GNU Privacy Guard (GPG) is the standard for OpenPGP. It is widely used for secure email, package signing, and asymmetric file encryption.

Encrypted secure notes representing GPG public-key encryption and private key management

gpg encrypt file

To encrypt a file for a specific recipient (assuming you have their public key imported):

Bash
gpg --encrypt --recipient "user@example.com" document.pdf

This creates a document.pdf.gpg file.

gpg decrypt file & decrypt pgp file

To decrypt a PGP or GPG file where you possess the corresponding private key:

Bash
gpg --decrypt document.pdf.gpg > document.pdf

Can I decrypt pgp message without key?

No. PGP relies on robust asymmetric cryptography. If you lose the private key (or the passphrase to unlock it), the data is permanently unrecoverable. Never trust services claiming to "decrypt pgp online" without a key—they are scams or phishing attempts designed to steal your keys.

gpg4win usage & kleopatra

For Windows users, Gpg4win is the standard distribution. It includes the CLI tools as well as a certificate manager called Kleopatra (e.g., version 4.0.0.250801 kleopatra). While you can use `gpg` in cmd/PowerShell, Kleopatra offers a GUI to manage the complex keyring process if you find CLI key management cumbersome.

7-Zip & Archive CLI

7-Zip is a powerful archive tool that includes strong AES-256 encryption. It is often used to compress and encrypt folders simultaneously.

Locked file cabinet representing password-protected 7-Zip encrypted archives

"7z" "-mem=aes256" (Encrypting Archives)

To create an encrypted ZIP archive via the Windows or Linux CLI:

CMD / Bash
7z a -pSecretPassword -mem=AES256 secure_archive.zip /path/to/folder

7z unzip with password

To extract an encrypted archive:

CMD / Bash
7z x secure_archive.zip -pSecretPassword

zip2john usage windows zip aes

If you forget a 7-Zip password, security professionals use tools like zip2john to extract the hash for cracking via Hashcat. The zip2john hashcat zip aes mode workflow involves extracting the "7zformat.txt" encryption flag data and running dictionary attacks against it. This underscores why choosing a strong, long passphrase is critical when using 7-Zip encryption.

Command-Line Method for Full Disk & USB Encryption

When searching for the best way to encrypt a usb flash drive so i can share files securely with clients, or wondering can i encrypt a usb drive via CLI, the native OS tools are powerful but require exact syntax.

USB flash drive security practices for protecting portable client files

How can i use windows to encrypt a usb drive (BitLocker CLI)

Windows provides manage-bde and PowerShell cmdlets for BitLocker. To encrypt a USB drive (e.g., drive E:) using the strongest XTS-AES 256-bit algorithm:

Windows 11 BitLocker and device encryption options for securing removable drives
PowerShell (Admin)
Enable-BitLocker -MountPoint "E:" -EncryptionMethod XtsAes256 -UsedSpaceOnly -PasswordProtector

You will be prompted to enter a secure password. The -UsedSpaceOnly flag speeds up the initial encryption process on new drives.

Decrypt command in cmd

To unlock the drive later via the command prompt:

CMD (Admin)
manage-bde -unlock E: -password

Encrypt usb drive on mac / Linux

On macOS, you would use diskutil (APFS encrypted). On Linux, cryptsetup (LUKS) is the standard for block device encryption.

Linux LUKS disk encryption workflow using cryptsetup command-line tools

Choosing the Right Encryption Software for Your Needs

CLI commands are powerful, but they have a fatal flaw for daily business use: human error. Typing the wrong syntax, misplacing a PGP key, or forgetting to run the script can leave sensitive data exposed.

For users asking about the best encryption software for protecting sensitive business files or the best free encryption software for usb drives, we recommend using dedicated GUI tools. Folder Lock is our top pick because it automates complex cryptographic processes into a seamless interface.

  • ✓ Cross-Platform Synchronization: Securely bridge your data across Windows, macOS, Android, and iOS environments without relying on unencrypted transfer methods.
  • ✓ Encrypted Cloud Integration: Automatically sync your secured vaults directly to Google Drive, Dropbox, or OneDrive, ensuring off-site backups are never exposed.
  • ✓ Self-Executing Portable Lockers: Generate secure USB drives or email attachments that authorized recipients can unlock without needing to pre-install the host software.
  • ✓ Granular Access Controls: Implement kernel-level restrictions that survive Safe Mode reboots, allowing you to define precise rules—such as making a document visible but immune to deletion or modification.
Folder Lock 10 encryption and privacy protection feature banner
[Folder Lock Dashboard UI showing AES-256 Lockers] Folder Lock 10 main dashboard for managing encrypted lockers and protected files

Beyond Basic Encryption: The GUI Advantage

While OpenSSL and BitLocker excel at raw cryptographic transformation, they lack peripheral security utilities essential for comprehensive privacy management. Modern encryption suites consolidate multiple protective layers into a single ecosystem.

For instance, securely deleting the original plaintext file after encryption is a critical step often overlooked by command-line users. Dedicated software includes secure file shredding algorithms (like the DoD 5220.22-M standard) to overwrite empty drive space, guaranteeing original drafts cannot be resurrected by advanced data recovery tools. Furthermore, these platforms often provide encrypted digital wallets for managing authentication credentials, financial details, and secure notes—a workflow that is highly impractical to maintain via terminal commands alone.

Folder Lock secure file shredding screen for permanently deleting plaintext files
Security Capability CLI Tools (OpenSSL / GPG) GUI Suite (Folder Lock)
Core Encryption AES-256 / RSA (Manual configuration) AES-256 (On-the-fly virtual drives)
Cloud Backup Sync Requires custom scripting Native integration (Dropbox, Google Drive)
Portable USB Security OS-dependent (BitLocker requires Windows) Self-executing cross-platform lockers
Data Wiping / Shredding Requires separate tools (e.g., `srm` or `shred`) Built-in DoD-standard shredding
Access Granularity Basic OS file permissions Kernel-level Read/Write/Delete restrictions

Hardware vs Software Encryption — Performance Tradeoffs

Many users ask: how to encrypt files without slowing down your computer?

The answer lies in the hardware vs. software debate. Software encryption (like OpenSSL or Folder Lock) utilizes your CPU to perform mathematical transformations. Historically, this caused a performance hit. Today, modern CPUs feature AES-NI (AES New Instructions)—hardware acceleration that allows software encryption to run with near-zero latency.

Hardware encryption (found on SEDs - Self Encrypting Drives, or specialized encrypted USBs) handles the cryptography entirely on a dedicated chip on the drive. This is faster and isolates the key from the OS, but is often much more expensive.

Digital and physical security comparison for hardware and software encryption

Encryption Compliance Requirements for Businesses

If you are managing data for a business, using the correct algorithms is a legal necessity.

Enterprise encryption and security tools supporting compliance and audit controls

Using openssl scripts is compliant, but proving compliance to an auditor is easier when using standardized enterprise data encryption software with audit logs.

Troubleshooting Common CLI Encryption Errors

"Bad decrypt" or "bad magic number" in OpenSSL

This is the most common error. It means you entered the wrong password, or you are trying to decrypt using a different algorithm flag (e.g., encrypting with `-aes-256-cbc` but decrypting with `-aes-256-gcm`). Verify your syntax and password.

BitLocker "The volume does not contain a recognized file system"

If you encrypted a USB drive on Windows 10 and plugged it into an older OS (like Windows 7), or a Mac, it cannot read the XTS-AES algorithm. You must decrypt it on a compatible Windows machine, or use multi-platform software like USB Secure.

USB Secure password dialog used to unlock an encrypted portable drive

Lost PGP Private Key

If you lose the private key, the data is gone. There is no backdoor. Always maintain an offline, physically secured backup of your private keys.

Frequently Asked Questions

What is the best method for encryption cli commands & tools reference? +

For symmetric file encryption, OpenSSL using AES-256-CBC is the standard. For secure communication and asymmetric encryption, GPG is the best method. For full disk or USB encryption on Windows, PowerShell BitLocker commands are recommended.

Can encrypted files be decrypted without the key? +

No. If standard AES-256 or RSA/PGP algorithms are used correctly, the encryption cannot be bypassed or "cracked" without the password or private key. This is why key management is critical.

Does encryption slow down my PC significantly? +

Modern encryption has minimal impact. Thanks to AES-NI hardware acceleration built into modern Intel and AMD processors, both file-level encryption and full disk encryption operate almost invisibly, with performance impacts usually under 3%.

Is open-source encryption software trustworthy? +

Yes, open-source tools like OpenSSL and GPG are highly trustworthy because their code is publicly audited by security experts worldwide. However, they lack user-friendly interfaces, which is why many opt for commercial data encryption software built on top of these open-source algorithms.

Can law enforcement decrypt AES-256 encrypted data? +

AES-256 itself has no backdoors. Unless they can compel you to hand over the password, or they discover the password written down or intercepted via malware (keyloggers), the cryptography itself cannot be broken by law enforcement.

How do i encrypt a usb flash drive? +

You can use the native OS command line (like Windows `manage-bde` for BitLocker), or for easier cross-platform compatibility, use specialized USB encryption software that creates an executable locker on the drive itself. These portable vaults allow authorized users to access data on any machine without needing to install the host software.

How to encrypt files for cloud storage? +

Never rely solely on a cloud provider's default security for highly sensitive information. You should encrypt files locally on your machine before uploading them. While you can write terminal scripts to encrypt directories before syncing, modern encryption software can automatically link secure local vaults directly to your Dropbox, OneDrive, or Google Drive, handling the cryptographic processes seamlessly in the background.

What happens to the original file after I encrypt it? +

If you use CLI tools to output a new encrypted file, the original plaintext file remains on your drive and must be securely deleted. Deleting it normally sends it to the recycle bin, where it can be easily recovered. It is highly recommended to use secure file shredding algorithms to overwrite the empty sectors, ensuring the unencrypted draft is permanently eradicated.

Our Verdict

Command-line encryption tools like OpenSSL, GPG, and BitLocker CLI offer unparalleled control and scriptability for IT professionals. They are free, heavily audited, and utilize unbreakable cryptography like AES-256.

However, for business teams, casual users, or anyone sharing encrypted USBs with clients, the command line introduces too much friction and risk of user error. For these scenarios, we highly recommend Folder Lock to handle the heavy cryptographic lifting behind a simple, foolproof interface.

Folder Lock 10 software boxshot for encrypted file and USB protection
Try Folder Lock Free → Get the Full Version →