Skip to content

Instantly share code, notes, and snippets.

@mperham
Last active April 16, 2024 12:31
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mperham/5f492a2233ed44d1bb2b to your computer and use it in GitHub Desktop.
Save mperham/5f492a2233ed44d1bb2b to your computer and use it in GitHub Desktop.
Golang high-level crypto APIs

Go has a number of low-level crypto APIs which check off marketing bullet-points (got FIPS supprt, check!) but is missing an high-level API usable by mere mortal programmers. Imagine you want to create a document, sign it and verify that document later. Now check out Go's crypto APIs and give up in frustration after an hour of Googling.

The API should encapsulate a half-dozen common operations and make them as easy as possible. Avoid choice where possible, just pick something reasonably secure in 2014 for me and use it! I'm speaking specifically of a few basic actions (yes, this API is very naive/non-idiomatic), call it crypto/easy:

  • Create me a public/private key pair and save it to the filesystem.
// create and persist a keypair to the current directory.
// this is just a one-time operation, now we have a keypair to use.
easy.CreateKeyPair()
  • Sign a document:
pair := easy.ReadKeyPair()
sig := easy.Sign(bytes, pair)
  • Verify a document:
pub := easy.ReadPublicKey(reader)
ok := easy.Verify(bytes, pub, sig)
  • Encrypt a document
  • Decrypt a document
  • etc

Ideally with this API I don't need to know anything about x509, asn1, elliptic curves, RSA/DSA, etc. Just as NaCl has tried to provide higher-level secure operations, Go (and most other languages too!) desperately need a simple, high-level API which hides the complexity inherent in most of the crypto/* packages today.

@mperham
Copy link
Author

mperham commented Sep 4, 2014

Here's code I came up with to solve my usecase:

https://github.com/mperham/gobox

@ereyes01
Copy link

I had the same problem and wrote a stupid simple (and maybe naive) wrapper around NaCl secretbox: https://guthub.com/ereyes01/cryptohelper

... And then I found this :) My approach is a little different, though. Have a look and see what you think.

@gwillem
Copy link

gwillem commented Apr 16, 2024

call it crypto/easy

Its called.. age!

https://github.com/FiloSottile/age

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment