gocrypt is a simple and efficient command line tool to encrypt and decrypt files using AES-128 or AES-256 encryption.
- Encrypt and decrypt files using AES-128 or AES-256 (GCM mode)
- Key can be provided via a file or the
GOCRYPT_KEY
environment variable - Easy integration in scripts and automation
- Cross-platform: works on Linux, macOS, and Windows
Version 2 (v2) introduced AES GCM (Galois/Counter Mode) encryption, which breaks compatibility with files encrypted using version 1 (v1).
- Files encrypted with v1 cannot be decrypted with v2
- Files encrypted with v2 cannot be decrypted with v1
This incompatibility is due to the fundamental change in the encryption mode from v1 to v2. AES GCM provides better security with authenticated encryption but requires a different format that is not backwards compatible.
$ gocrypt help
Tool to encrypt/decrypt files using AES128 or AES256.
Usage:
gocrypt [command]
Available Commands:
completion Generate the autocompletion script for the specified shell
dec decrypt file in AES 128/256
enc encrypt file in AES 128/256
help Help about any command
version print version of gocrypt
Flags:
-h, --help help for gocrypt
Use "gocrypt [command] --help" for more information about a command.
# Encrypt a file with a 32-byte key (AES-256)
gocrypt enc --i input.txt --o encrypted.bin --k keyfile.txt
# Decrypt a file
gocrypt dec --i encrypted.bin --o decrypted.txt --k keyfile.txt
- For AES-128, the key must be exactly 16 bytes (characters)
- For AES-256, the key must be exactly 32 bytes (characters)
- The key can be provided in a file or via the
GOCRYPT_KEY
environment variable
Even though this tool is maintained, for most use-cases you should consider using age which is a more modern and secure encryption tool.
Download the binary from the releases section. There is no official Docker image, but you can add the binary to your own Docker image if needed.
brew tap sgaunet/homebrew-tools
brew install sgaunet/tools/gocrypt
FROM sgaunet/gocrypt:latest as gocrypt
FROM alpine:latest
COPY --from=gocrypt /gocrypt /usr/local/bin/gocrypt
...
The project includes automated tests for both small and large files. See the tests/
directory for details.
task tests
MIT License