To decrypt a file you need to know how it was encrypted, because each tool uses its own command: gpg -o report.txt -d report.txt.gpg for GnuPG files, openssl enc -d for OpenSSL files, cipher /d for Windows EFS, and manage-bde for BitLocker drives. In every case you also need the matching password, private key or recovery key; without it, the file cannot be decrypted.
Find your case in the table, then jump to that section.
| What you have | Tool | Decrypt with |
|---|---|---|
A .gpg, .pgp or .asc file | GnuPG | gpg -o out -d file.gpg |
A file made with openssl enc (often .enc) | OpenSSL | openssl enc -d -cipher ... -in file -out out |
| A file in a Windows folder that is marked encrypted | EFS | cipher /d file |
| A whole drive that asks for a password or recovery key | BitLocker | manage-bde -unlock or manage-bde -off |
How to decrypt a GPG file (.gpg, .pgp, .asc)
gpg -o report.txt -d report.txt.gpg
-d is --decrypt. The GnuPG manual says it writes the result "to STDOUT (or the file specified with --output)", so without -o the decrypted content is printed to the terminal instead of saved. The manual also says the command "never writes to the filename which is included in the file" and "rejects files that don't begin with an encrypted message", so naming the output yourself is required if you want a file.
GPG asks for a passphrase if the file was encrypted with one, or finds your private key automatically if it was encrypted to your public key. If the file was also signed, the manual notes that "the signature is also verified" during decryption.
To decrypt several files at once, use --decrypt-files, which the manual defines as "Identical to --multifile --decrypt":
gpg --decrypt-files *.gpg
If you aren't sure which key a file needs, list the recipients without decrypting. The manual describes --list-only as skipping "the actual decryption pass" for "a fast listing of the encryption keys":
gpg --list-only report.txt.gpg
GPG is available on Linux (package gnupg), and on Windows through Git Bash or Gpg4win. For creating these files and the errors you may hit, such as decryption failed: Bad session key or No secret key, see how to encrypt a file with GPG.
How to decrypt a file with OpenSSL
OpenSSL's enc command decrypts with -d, documented as "Decrypt the input data". Every option that affects the key must match what was used to encrypt. An example for a file encrypted with AES-256-CBC and a password:
openssl enc -d -aes-256-cbc -pbkdf2 -in secret.enc -out secret.txt
OpenSSL prompts for the password. Notes on the options:
-inand-outname the input and output files; both default to standard input and output.- The cipher (here
-aes-256-cbc) has to be the one used for encryption. The documentation's decryption examples all repeat the encryption cipher, so ask the sender, or check the script that made the file. -pbkdf2selects the PBKDF2 key derivation, with a default of 10000 iterations unless-itersays otherwise. If the file was encrypted with-iter, pass the same number. A file made without-pbkdf2must be decrypted without it.- The digest used to turn the password into a key defaults to SHA-256 (
-md). The documentation's history section says the default was MD5 before OpenSSL 1.1.0, so a file from an older system may need-md md5. - To pass the password from the environment instead of a prompt, use
-pass env:VARNAME, which follows the argument format in the OpenSSL passphrase documentation.
A wrong password or wrong options usually produces garbage or an error rather than a clear "wrong password" message. The documentation explains why: the padding check is weak, and it says random data passes it roughly 1 time in 256. So a successful run is not proof that the output is correct. Open the result and look at it.
How to decrypt a file on Windows (EFS)
The Encrypting File System (EFS) encrypts files and folders on NTFS volumes, tied to your Windows account. Check the state of the current folder first:
cipher
Microsoft's documentation says encrypted files and directories are marked with an E and unencrypted ones with a U. To decrypt a file or folder, use /d, which "Decrypts the specified files or directories":
cipher /d Private
cipher /d /s:C:\work\Private
Here Private is a folder name from the documentation's example, and /s:<directory> applies the operation to all subdirectories. Add /h to include files with hidden or system attributes, which are skipped by default.
Two cautions from the same page. If a parent directory is not encrypted, an encrypted file can become decrypted when it is modified. And EFS depends on your EFS certificate and key: back them up with cipher /x backup-file, which "backs up the EFS certificate and keys to the specified file name". Without that key, for example after reinstalling Windows with no backup, the files cannot be opened. An administrator may be able to recover them if a recovery agent was set up beforehand: the documentation says the recovery agent's .pfx file can be imported "to recover individual files".
How to decrypt a BitLocker drive
BitLocker encrypts a whole volume, so there is no per-file decrypt command. There are two different jobs: unlocking a locked drive so you can read it, and turning BitLocker off so the drive is decrypted for good.
Unlock a locked drive
From an elevated Command Prompt, using the examples in Microsoft's manage-bde -unlock page for drive E:
manage-bde -unlock E: -password
manage-bde -unlock E: -recoverypassword xxxxxx-xxxxxx-xxxxxx-xxxxxx-xxxxxx-xxxxxx-xxxxxx-xxxxxx
manage-bde -unlock E: -recoverykey F:\Backupkeys\recoverykey.bek
The first prompts for the drive's password. The second takes the 48-digit recovery password, which the documentation says "must be written exactly as shown including dashes". The third uses a .bek recovery key file saved to a USB drive or backup folder.
Turn BitLocker off
manage-bde -off C:
Microsoft describes this as: "Decrypts the drive and turns off BitLocker. All key protectors are removed when decryption is complete." Decryption of a large drive takes a while, and the drive must stay powered until it finishes. If you only want to compare the two systems before deciding, see BitLocker vs FileVault.
What if you don't have the key or password?
Then the file stays encrypted. That is the point of encryption, and the tools above have no bypass. Realistic options, roughly in order:
- Look for the key or recovery key. BitLocker recovery keys are often saved to a Microsoft account, a work or school account, or a printout. A GPG private key may be in another keyring or a backup of the
.gnupgfolder. - Ask whoever encrypted it. They may have the passphrase, or can re-encrypt the file for you.
- Try passwords you actually used. Check your password manager first. See how long it takes to crack a password for why guessing a strong one is not realistic.
Programs that promise to decrypt any file without credentials are, at best, brute-force guessers and, at worst, malware. Encrypted files that appeared after an attack are a different problem: see what ransomware is.
If decryption fails
gpg: decryption failed: No secret key: the file was encrypted to a key that isn't in your keyring. Rungpg --list-onlyon it and compare the key ID withgpg --list-secret-keys --keyid-format long.- Garbage or an OpenSSL error after the password: the cipher,
-pbkdf2,-iteror-mdsetting doesn't match what was used to encrypt. cipher /dreports errors on some files: by default it continues past errors; add/bto abort on the first one and see which file is the problem.- Not sure the file is encrypted at all: an encrypted file's contents look like random bytes in a text editor. A file that opens as readable text, or fails to open in its normal program, may simply be corrupted or the wrong type.
Frequently asked questions
- Can I decrypt a file without the password or key?
- No, not in any practical way. Modern encryption is designed so that the file is unreadable without the key or passphrase. If you forgot a passphrase, the only options are to remember it, find a backup of the key or recovery key, or ask whoever encrypted the file. Be wary of any tool that claims to decrypt files without credentials.
- How do I know which encryption a file uses?
- Start with the file extension and where the file came from: .gpg, .pgp or .asc usually mean GnuPG, a lock icon or green filenames in Windows Explorer mean EFS, and an entire drive that asks for a password or recovery key is BitLocker. For a GPG file, gpg --list-only shows which keys it was encrypted to without decrypting it.
- Is decrypting a file the same as unlocking a password-protected ZIP or PDF?
- They are related but use different tools. Password-protected ZIP and PDF files are opened with the program that created them (an archiver or a PDF reader) and the password. The commands in this article are for files encrypted by GnuPG and OpenSSL, and for Windows EFS and BitLocker.
- Does decrypting delete the encrypted copy?
- With gpg and openssl, no: the encrypted file stays and a new decrypted file is written, so you have both. With cipher /d on Windows, the file itself is converted back to plain data in place, and with manage-bde -off the whole drive is decrypted.