The Wayback Machine - https://web.archive.org/web/20250607121350/https://www.reddit.com/r/golang/
Skip to main content
r/golang icon

r/golang

members
online

Show HN: rusjoan/streamcrypt – Add AES-GCM Encryption to Any Go Stream (Including GZIP) with Little Overhead and the Ability to Append Later • Show HN: rusjoan/streamcrypt – Add AES-GCM Encryption to Any Go Stream (Including GZIP) with Little Overhead and the Ability to Append Later

I kept hitting the same problem in my data pipeline: how to efficiently encrypt compressed streams without buffering entire files or large chunks, while keeping the ability to append data later without corrupting existing content. The existing solutions either:

  1. Required loading everything into memory (crypto/aes + bytes.Buffer), or

  2. Broke streaming capabilities (I mean true streaming with tiny buffers and the ability to append at any time)

So I built rusjoan/streamcrypt â€“ a minimal Go library that:
✅ Wraps any io.Reader/io.Writer with AES-GCM encryption
✅ Preserves streaming (constant memory usage)
✅ Works seamlessly with gzip/zstd
✅ Supports appending data to existing payloads without corruption
✅ Adds only 32 bytes per chunk (~13% overhead for JSON+GZIP)

Why this matters:

  • Process TB-scale data with KB-scale RAM

  • Encrypt before/after compression without temp files

  • Zero dependencies (pure Go stdlib)

Basic usage:

var enc, _ = streamcrypt.NewEncryptor(secret)

// Encrypting gzip stream
gzip.NewWriter(enc.Seal(file))

// Decrypting
gzip.NewReader(enc.Open(file))

Benchmarks:

// allocations
goos: darwin
goarch: arm64
pkg: github.com/rusjoan/streamcrypt
cpu: Apple M1 Pro
    BenchmarkTee
    BenchmarkTee/rnd->encryptor->discard
    BenchmarkTee/rnd->encryptor->discard-10     765747      1525 ns/op      0 B/op      0 allocs/op
PASS

// heap grow
=== RUN   TestMemoryOverhead
    streamcrypt_test.go:218: Size: 16.0 KiB, Memory delta: 704 B
    streamcrypt_test.go:218: Size: 1.0 MiB, Memory delta: 576 B
    streamcrypt_test.go:218: Size: 32.0 MiB, Memory delta: 576 B
    streamcrypt_test.go:218: Size: 1.0 GiB, Memory delta: 576 B
--- PASS: TestMemoryOverhead (2.42s)
PASS

Next version plans:

  • Allow custom encryption methods beyond built-in AES-GCM

Would love community feedback on:

  • Real-world use cases I haven't considered

  • Any similar solutions I might have missed (I did thorough research)

  • Ways to further reduce the overhead

This is my first open-source library after a long time of being read-only, so I'd really appreciate your support!

GitHub | GoDoc


Learn Event-Driven Go
Learn Event-Driven Go


My company is pushing Go for web backend. I need opinions as not a Go Developer • My company is pushing Go for web backend. I need opinions as not a Go Developer
discussion

Hello!

I'm a backend \ frontend web developer in a big tech company (not world-wide big tech but big enough in my country). Historically so happened that our company has been using JavaScript and TypeScript for everything and a lot of in-house solutions, libs etc were based on that. It's been working for years, our RPS is pretty high, I don't know just how much it is high (not in a position to know that information in details) but I know for a fact we got over several million costumers, over 200 microservices in production.

Fairly recently someone from "bosses league" so to say has been pushing we move everything to Go, it's been sold there because of ever growing load and our resources are expensive and not unlimited - that's basically the explanation we got.

Very few of the current devs in the company have ever worked with Go so they plan to fund Go courses for everyone willing. It is not said outright but I guess those who won't learn Go at some point will be laid off.

I'm not exactly against this idea of learning Go, but I'd like to know what I "win" as a developer aside from a new skill in my CV. I've already googled some stuff but would be cool if someone sold it to me so to say