go-eyaml

eyaml encryption in pure Go โ€” PKCS7 and GPG encrypt/decrypt for hiera-eyaml data, CGO-free.

pure Go ยท zero cgo ENC[PKCS7,โ€ฆ] tokens ENC[GPG,โ€ฆ] tokens AES-256-CBC RSA PKCS#1 v1.5 CMS EnvelopedData (RFC 5652) createkeys 100% coverage 6 arches + wasm
Documentation GitHub
Documentation (MkDocs Material + mike) License: BSD-3-Clause Go 1.26.4+ Coverage 100%

go-eyaml is a pure-Go (CGO_ENABLED=0) implementation of the two encryption schemes used by Puppet's hiera-eyaml: the ENC[PKCS7,<base64>] and ENC[GPG,<base64>] token formats that carry an encrypted value inside otherwise-plaintext YAML. For PKCS7, a random 256-bit AES content key encrypts the plaintext with AES-256-CBC, the content key is wrapped for the recipient with RSA PKCS#1 v1.5 under an X.509 certificate, and the whole thing is serialised as a CMS EnvelopedData (RFC 5652) token, built exclusively on the standard library's crypto packages. For GPG, a session key is public-key-encrypted to recipient OpenPGP keys exactly as gpg --encrypt does, using the pure-Go ProtonMail/go-crypto/openpgp implementation. Both stay CGO_ENABLED=0. 100% coverage, six arches and WebAssembly.

Token format ready

IsToken / ParseToken / FormatToken for the ENC[PKCS7,<base64>] tokens hiera-eyaml embeds in YAML, tolerant of whitespace-wrapped values.

PKCS7 encryptor ready

A random AES-256 content key (AES-256-CBC, PKCS#7 padding) wrapped with RSA PKCS#1 v1.5 under an X.509 certificate, serialised as a CMS EnvelopedData ContentInfo โ€” mirroring hiera-eyaml’s pkcs7 encryptor.

Key management ready

CreateKeys generates the RSA keypair and self-signed certificate that eyaml createkeys produces; LoadPrivateKey / LoadCertificate read PEM / PKCS8 material; LoadGPGKeyRing reads OpenPGP keyring material.

PKCS7 crypto ready

Built on crypto/rsa, crypto/x509, crypto/aes, crypto/cipher, crypto/rand, encoding/pem and encoding/asn1; the PKCS#7 / CMS structure is hand-assembled โ€” no third-party crypto, no cgo.

GPG encryptor ready

NewGPG mirrors hiera-eyaml’s gpg (GPGME) encryptor on the pure-Go, CGO-free ProtonMail/go-crypto/openpgp, producing ENC[GPG,<base64>] tokens byte-for-byte interoperable with real gpg --encrypt / --decrypt.

The hiera-eyaml encryption engine of the go-eyaml org: token format, PKCS7 and GPG encryptors, and key generation โ€” CGO-free, PKCS7 on the Go standard library's crypto primitives alone, GPG adding one pure-Go OpenPGP dependency. Part of the pure-Go Puppet stack alongside go-facter, go-hiera, go-pcore and go-puppet.