encryption

package
v0.0.0-...-5c87083 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2022 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// TIME complexity parameter for Argon2, used by PasswordHash.
	TIME uint32 = 8

	// MEMORY complexity parameter for Argon2, used by PasswordHash.
	MEMORY uint32 = 32 * 1024

	// SALTLEN length of salt given by GenerateSalt.
	SALTLEN uint32 = 32

	// KEYLEN length of key generated by PasswordHash.
	KEYLEN uint32 = 32 // 32-bytes keys are used with AES-256
)

Variables

This section is empty.

Functions

func CheckSum

func CheckSum(message []byte) []byte

CheckSum checksum of the message.

func Decrypt

func Decrypt(key, message []byte) ([]byte, error)

Decrypt a message given a secret key.

func DefaultPasswordCharRange

func DefaultPasswordCharRange() []uint8

DefaultPasswordCharRange returns the default ASCII characters to be used with GeneratePassword().

func Encrypt

func Encrypt(key, message []byte) ([]byte, error)

Encrypt a message given a secret key.

func GeneratePassword

func GeneratePassword(length int, characters []uint8) string

GeneratePassword generates a random sequence of the given ASCII characters.

func GenerateRandomBytes

func GenerateRandomBytes(len uint32) []byte

GenerateRandomBytes generates a random sequence of bytes.

func GenerateSalt

func GenerateSalt() []byte

GenerateSalt generates a random sequence of bytes that can be used as a password salt.

func GetPasswordCharRange

func GetPasswordCharRange(passwordStrength PasswordStrength) (charRange []uint8)

GetPasswordCharRange returns the appropriate char-range for the given PasswordStrength.

func Hmac

func Hmac(key, message []byte) []byte

Hmac of the message based on the given key.

func PasswordHash

func PasswordHash(password string, salt []byte, threads uint8) []byte

PasswordHash creates a cryptographical hash of the salted password.

func VerifyHmac

func VerifyHmac(mac1, mac2 []byte) bool

VerifyHmac verifies the two given HMAC's are equal. Returns true if equal, false otherwise.

Types

type PasswordStrength

type PasswordStrength int

PasswordStrength specifies the desired strength of a password generated with GeneratePassword.

const (
	// WEAK policy includes only standard latin alphabet characters.
	WEAK PasswordStrength = iota + 1
	// ALPHANUMERIC policy includes all alphanumeric characters.
	ALPHANUMERIC
	// NORMAL policy includes alphanumeric characters plus standard ASCII symbols.
	NORMAL
	// STRONG policy includes extended ASCII characters and standard ASCII symbols.
	STRONG
	// STRONGEST policy includes extended ASCII characters and extended ASCII symbols.
	STRONGEST
)

Jump to

Keyboard shortcuts

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