# README
Crypto Tooling
This package github.com/Scalingo/go-utils/crypto
aims at providing common crypto primitive helpers.
Secret Generator
// Generate keys with different formats
crypto.CreateKey(size int) ([]byte, error)
crypto.CreateKeyString(size int) (string, error)
crypto.CreateKeyBase64String(size int) (string, error)
// Parse hex-string key back to binary
crypto.ParseKey(key string) ([]byte, error)
Symmetric Block Encryption (AES-CFB)
crypto.Encrypt(key, plaintext []byte) ([]byte, error)
crypto.Decrypt(key, ciphertext []byte) ([]byte, error)
HMAC-SHA Signature
crypto.HMAC256(key, payload []byte) ([]byte, error)
crypto.HMAC512(key, payload []byte) ([]byte, error)
Data Stream Encryption (AES-256-CTR)
crypto.NewStreamEncrypter(encryptionKey, hmacKey []byte, plaintext io.Reader) (*StreamEncrypter, error)
crypto.NewStreamDecrypter(encryptionKey, hmacKey []byte, ciphertext io.Reader) (*StreamDecrypter, error)
- Both
StreamEncrypter
andStreamDecrypter
areio.Reader
- Calling
Read
on them will be blocking if no input is provided - They'll return
io.EOF
once the input returnsio.EOF
.
# Functions
CreateKey creates a key of a given size by reading that much data off the crypto/rand reader.
CreateKeyBase64String generates a new key and returns it as a base64 std encoding string.
CreateKeyString generates a new key and returns it as a hex string.
Decrypt decrypts data with the given key.
Encrypt encrypts data with the given key.
HMAC256 sha256 hashes data with the given key.
HMAC512 sha512 hashes data with the given key.
NewStreamDecrypter creates a new stream decrypter.
NewStreamEncrypter creates a new stream encrypter.
ParseKey parses a key from an hexadecimal representation.
# Constants
DefaultKeySize is the size of keys to generate for client use.
IVSize is the size of the IV prefix.
YYYY + MM + DD + :.
# Structs
StreamDecrypter is a decrypter for a stream of data with authentication.
StreamEncrypter is an encrypter for a stream of data with authentication.
StreamMeta is metadata about an encrypted stream.