crypto

package
v1.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 30, 2021 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

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.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckCSPRNG

func CheckCSPRNG()

CheckCSPRNG will see if it's possible to generate a cryptographically secure pseudorandom number. If not then this will panic.

Types

type AESGCM added in v1.1.0

type AESGCM struct {
	// contains filtered or unexported fields
}

AESGCM provides authenticated encryption using AES as the cipher wrapped in Galois Counter Mode.

func NewAESGCM added in v1.1.0

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.

func (*AESGCM) Decrypt added in v1.1.0

func (a *AESGCM) Decrypt(p []byte) ([]byte, error)

Decrypt returns the decrypted bytes of the given payload.

func (*AESGCM) Encrypt added in v1.1.0

func (a *AESGCM) Encrypt(p []byte) ([]byte, error)

Encrypt returns the encrypted bytes of the given payload.

type 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.

func (*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.

func (*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.

func (*Hasher) Init

func (h *Hasher) Init() error

Init initializes the hasher for hasing of numbers.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL