crypto
v1.1.1
Documentation
pkg.go.dev ↗Package crypto implements functions for hashing, encrypting, and decrypting data.
Encryption, and decryption uses the underlying crypto/aes, crypto/cipher,and crypto/rand packages from the stdlib.
Hashing is supported via use of the speps/go-hashids library.
Functions
CheckCSPRNG
func CheckCSPRNG()
CheckCSPRNG will see if it's possible to generate a cryptographically secure pseudorandom number. If not then this will panic.
Types
AESGCM
type AESGCM struct {
// contains filtered or unexported fields
}
AESGCM provides authenticated encryption using AES as the cipher wrapped in Galois Counter Mode.
NewAESGCM
func NewAESGCM(password, salt []byte) (*AESGCM, error)
NewAESGCM returns a new block cipher for authenticated encryption. This derives a HMAC-SHA-256 based PBKDF2 key from the given password and salt.
AESGCM.Decrypt
func (a *AESGCM) Decrypt(p []byte) ([]byte, error)
Decrypt returns the decrypted bytes of the given payload.
AESGCM.Encrypt
func (a *AESGCM) Encrypt(p []byte) ([]byte, error)
Encrypt returns the encrypted bytes of the given payload.
Hasher
type Hasher struct {
// Salt is the additional data to use when generating a hash.
Salt string
// Length is the minimum length of hashes that should be generated.
Length int
// Alphabet is the sequence of characters that should be chosen from when a
// hash is being generated. If empty then the default a-zA-Z0-9 alphabet
// will be used.
Alphabet string
// contains filtered or unexported fields
}
Hasher is the type for generating hash ids based on a sequence of numbers, based on the specified alphabet and length.
Hasher.Hash
func (h *Hasher) Hash(i ...int) (string, error)
Hash returns the hash of the given numbers. This will return an error if the Hasher has not yet been initialized, or any other underlying errors from hashing.
Hasher.HashNow
func (h *Hasher) HashNow() (string, error)
HashNow returns the hash of the current UNIX nano timestamp. This will return an error if the Hash has not yet been initialized, or any other underlying errors from hashing.
Hasher.Init
func (h *Hasher) Init() error
Init initializes the hasher for hasing of numbers.