A pure-Go implementation of the Cryptographic Message Syntax (CMS, RFC 5652):
encrypt to X.509 certificate holders, decrypt with the matching private key, sign, and
verify against an offline certificate policy. No cgo. Builds for GOOS=js GOARCH=wasm and
GOOS=wasip1 GOARCH=wasm.
The library implements one fixed algorithm profile. Everything outside it is refused with a typed error naming the OID; nothing is negotiated.
| Structure | Algorithms |
|---|---|
EnvelopedData (RFC 5652 §6) and AuthEnvelopedData (RFC 5083) |
content encryption AES-128-GCM and AES-256-GCM (RFC 5084); AES-CBC accepted on decrypt only, behind an option, for interop with legacy producers |
KeyTransRecipientInfo |
RSA-OAEP with SHA-256 and MGF1-SHA-256 (RFC 3560); RSA keys ≥ 2048 bits |
KeyAgreeRecipientInfo |
ephemeral-static ECDH on P-256 and P-384 (RFC 5753), ANSI X9.63 KDF with SHA-256/384, AES key wrap (RFC 3394) |
SignedData (§5) |
ECDSA P-256/SHA-256 and P-384/SHA-384; RSA-PSS with SHA-256; Ed25519 (RFC 8419). Signed attributes are mandatory: content-type, message-digest, signing-time, ESSCertIDv2 (RFC 5035). Attached and detached content. |
| Encoding | strict DER on output; DER and the indefinite-length BER that openssl cms streams by default on input |
| Recipient selection | IssuerAndSerialNumber and SubjectKeyIdentifier |
| Certificate policy | offline only: caller-supplied trust anchors, intermediates and CRLs; no network access anywhere in the library; EKU and validity checked at a caller-supplied time |
var envelope bytes.Buffer
if err := cryptomsg.Encrypt(&envelope, zipFile, recipientCerts, nil); err != nil { … }
sig, err := cryptomsg.Sign(bytes.NewReader(envelope.Bytes()), signerKey, signerChain,
&cryptomsg.SignOptions{Detached: true})
policy := &cryptomsg.Policy{Roots: roots, Intermediates: intermediates, CRLs: crls, Time: time.Now()}
if _, err := cryptomsg.Verify(sig, bytes.NewReader(envelope.Bytes()), policy); err != nil { … }
var plaintext bytes.Buffer
err = cryptomsg.Decrypt(&plaintext, &envelope, myCert, myKey, nil)Encrypt buffers the plaintext and Decrypt the envelope (GCM authenticates the content as a
whole and nothing is released before the tag verifies), so peak memory is about twice the
content size. Interoperability is tested in both directions against OpenSSL 3.5.4 and against
committed Bouncy Castle 1.80 fixtures. DecryptOptions.MaxSize bounds how much of an untrusted envelope is read before
parsing; zero (the default) leaves it unbounded.
$ cryptomsg inspect -in package.cms
type: AuthEnvelopedData
content encryption: 2.16.840.1.101.3.4.1.46
recipients: 2
[0] issuer=CN=Example CA serial=4242 key algorithm 1.2.840.113549.1.1.7 (supported)
[1] ski=0a1b2c3d key algorithm 1.3.132.1.11.1 (supported)
Parse returns a typed view of a CMS object — recipients, algorithms, signer certificates —
without any key, so a caller can report "encrypted for 3 recipients, signed by CN=…" before
deciding to decrypt. The cryptomsg CLI (encrypt, decrypt, sign, verify, inspect) is
a thin wrapper over the library.
openssl cms defaults to algorithms outside the profile — PKCS#1 v1.5 for RSA recipients,
the SHA-1 ECDH KDF for EC recipients, no signingCertificateV2 — and cryptomsg refuses those
by OID. An OpenSSL producer must ask for the profile's options; a consumer needs only -binary
so nothing is treated as text:
# encrypt for cryptomsg (streamed BER is fine; cryptomsg normalises it)
openssl cms -encrypt -binary -aes-256-gcm -outform DER -in model.zip -out model.zip.p7m \
-recip rsa.crt -keyopt rsa_padding_mode:oaep -keyopt rsa_oaep_md:sha256 \
-recip ec.crt -keyopt ecdh_kdf_md:sha256 # ecdh_kdf_md:sha384 for P-384
# sign for cryptomsg (-cades adds the mandatory signingCertificateV2)
openssl cms -sign -binary -cades -outform DER -signer signer.crt -inkey signer.key \
-in model.zip.p7m -out model.zip.p7m.sig
# open what cryptomsg produced
openssl cms -decrypt -binary -inform DER -in model.zip.p7m -recip ec.crt -inkey ec.key -out model.zip
openssl cms -verify -binary -inform DER -in model.zip.p7m.sig -content model.zip.p7m -CAfile ca.crt -out /dev/nullOpenSSL before 3.5 cannot sign with Ed25519 in CMS; verify such signatures with cryptomsg or Bouncy Castle.
Pre-release; the API may change until v0.1.0. See CHANGELOG.md,
docs/design.md for the structure and policy choices, docs/fips.md
for the FIPS 140-3 position, and SECURITY.md for reporting vulnerabilities.
Apache-2.0. See LICENSE.