Documentation
¶
Overview ¶
Package tinycrypto provides some very simple helpers for encrypting and decrypting data with minimal fuss, either directly, or through a `Keyset`, which allows working with multiple encryption keys easily when you want to be able to smoothly rotate new keys in over time.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Encrypt ¶
Encrypt leverages AES-GCM authenticated encryption (encrypts and signs). https://en.wikipedia.org/wiki/Galois/Counter_Mode NOTE: This is for safely storing secret keys. If you need to hash a password, use the acrypt lib.
func GenerateRandomBytes ¶
GenerateRandomBytes generates cryptographically secure pseudo-random numbers.
func HashForString ¶
HashForString converts a string into a 256-bit hash, usable as a secret key for symmetric crypto. NOTE: This is for safely stored secret keys. Do NOT use this for passwords.
func RandUInt32 ¶
RandUInt32 returns a randomly-generated BigEndian 32-bit unsigned integer. It uses the crypto package, and these values are frequently used as nonces.
Types ¶
type CryptoKeyStore ¶
type CryptoKeyStore interface { GetCryptoKeyset(name string) (keyset *Keyset, err error) PutCryptoKeyset(name string, keyset *Keyset) (err error) }
CryptoKeyStore provides a generic interface for storing and retrieving cryptographic keys (that themselves should be encrypted at rest).
type Key ¶
Key wraps an encryption key value to be used with `Keyset`s.
func NewKey ¶
NewKey creates a `Key`, for use with `Keyset`'s, with the given 256-bit value, and sets the creation date.
func NewRandomKey ¶
NewRandomKey creates a `Key`, for use with `Keyset`s, with a random 32-byte key value, and sets the creation date.
type Keyset ¶
A Keyset stores multiple keys, allowing clients to rotate keys if required. The Keysets get persisted in a name-value store, so the type of Key in a given Keyset is generally fixed/known based on the name used to fetch it. If clients need to support Keysets of various types on a given API (which get persisted using the same name), they can optionally provide a TypeID.
func NewKeysetWithKey ¶
func (*Keyset) Decrypt ¶
Decrypt attempts to decrypt an AES-GCM encrypted value using each unexpired key in the given keyset until decryption is successful.