gocrypt is a command line tool to encrypt/decrypt file in AES128/256/512.
Find a file
Sylvain 582abe681b
Some checks failed
Generate coverage badges / generate-badges (push) Has been cancelled
linter / linter (push) Has been cancelled
snapshot / goreleaser-snapshot (push) Has been cancelled
Vulnerability Scan / Run govulncheck (push) Has been cancelled
ci: update checkout step to include persist-credentials option
ci: update checkout step to include persist-credentials option
2025-11-26 21:36:08 +01:00
.github ci: update checkout step to include persist-credentials option 2025-11-26 21:34:58 +01:00
.vscode 11 ofb encryption is deprecated (#20) 2025-05-09 22:19:51 +02:00
cmd feat: add linter configuration and update command files for improved linting and code quality (#25) 2025-08-06 23:19:06 +02:00
doc doc: add a gif 2023-11-20 21:06:43 +01:00
internal/aes feat: add linter configuration and update command files for improved linting and code quality (#25) 2025-08-06 23:19:06 +02:00
tests 11 ofb encryption is deprecated (#20) 2025-05-09 22:19:51 +02:00
.gitignore ci: refactor (#31) 2025-09-06 20:40:04 +02:00
.golangci.yml feat: add linter configuration and update command files for improved linting and code quality (#25) 2025-08-06 23:19:06 +02:00
.goreleaser.yml release: update goreleaser configuration and improve brews section (#27) 2025-08-22 21:15:35 +02:00
.pre-commit-config.yaml build: update pre-commit configuration 2023-08-25 14:43:22 +02:00
Dockerfile release: add docker image 2024-03-12 21:48:14 +01:00
go.mod build(deps): bump github.com/spf13/cobra from 1.9.1 to 1.10.1 (#32) 2025-10-01 13:55:09 +02:00
go.sum build(deps): bump github.com/spf13/cobra from 1.9.1 to 1.10.1 (#32) 2025-10-01 13:55:09 +02:00
LICENSE Initial commit 2022-04-01 09:34:17 +02:00
main.go feat: add linter configuration and update command files for improved linting and code quality (#25) 2025-08-06 23:19:06 +02:00
README.md doc: add CI badges for linter, coverage, snapshot, and release builds in README (#29) 2025-09-04 22:14:38 +02:00
Taskfile.yml chore: rename linter task to lint in Taskfile and update workflow reference 2025-11-26 21:31:35 +01:00
Taskfile_dev.yml taskfile: rename some tasks 2023-08-31 22:16:03 +02:00

Go Report Card GitHub release GitHub Downloads Coverage Badge linter coverage Snapshot Build Release Build GoDoc License

Gocrypt

gocrypt is a simple and efficient command line tool to encrypt and decrypt files using AES-128 or AES-256 encryption.

Features

  • 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 Compatibility

⚠️ Important Breaking Change ⚠️

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.

Usage

$ 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.

Example

# 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

Key Format

  • 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

Demo

Demo

Recommendation

Even though this tool is maintained, for most use-cases you should consider using age which is a more modern and secure encryption tool.

Install

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.

With Homebrew

brew tap sgaunet/homebrew-tools
brew install sgaunet/tools/gocrypt

Use in Docker

FROM sgaunet/gocrypt:latest as gocrypt

FROM alpine:latest
COPY --from=gocrypt /gocrypt /usr/local/bin/gocrypt
...

Tests

The project includes automated tests for both small and large files. See the tests/ directory for details.

task tests

License

MIT License