crypto

Guided tour · Crypto · pkg.go.dev →

The root crypto package. Defines Hash (an enum of registered hash funcs), the Signer and Decrypter interfaces, and little else. Real work happens in subpackages.

Hash — an enum of algorithms

Subpackages (crypto/sha256, crypto/sha512, crypto/md5...) register themselves on import. crypto.Hash lets generic code name them.

Pick a hash by name

h := crypto.SHA256.New()   // requires import of crypto/sha256
io.Copy(h, f)
fmt.Printf("%x\n", h.Sum(nil))

Signer interface

crypto.Signer is the abstraction used by TLS, ssh, and PKI code: anything with a private key you can sign with. *rsa.PrivateKey, *ecdsa.PrivateKey, ed25519.PrivateKey all implement it.