Documentation ¶
Index ¶
- Variables
- func CreateToken(key []byte, id string) (token string, err error)
- func Decrypt(cipherText, key []byte) (decrypted []byte, err error)
- func DecryptFromString(cipherTextStr string, key []byte) (decrypted []byte, err error)
- func Encrypt(plainText, key []byte) (encrypted []byte, err error)
- func EncryptToString(plainText, key []byte) (string, error)
- func PassphraseToKey(passphrase string) (key []byte)
- func RandomString(length int) (string, error)
- func ValidateToken(token string, key []byte, id string, lifetime time.Duration) error
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // ErrTokenInvalid occurs when `ValidateToken` failed to decode the token ErrTokenInvalid = errors.New("crypto: invalid token, failed to decode") // ErrTokenExpired occurs when `ValidateToken` succeeded // to decode the token but it's expired ErrTokenExpired = errors.New("crypto: token expired") // ErrTokenNoIDMatch occurs when `ValidateToken` succeeded // to decode the token but its ID does not match the validation request ErrTokenNoIDMatch = errors.New("crypto: token ID does not match") // ErrCipherTooShort occurs when `Decrypt` does not // have input of enough length to decrypt using AES256 ErrCipherTooShort = errors.New("crypto: cipher plainText is too short for AES encryption") )
Functions ¶
func CreateToken ¶
CreateToken creates an encrypted token that can be validated later. `id` parameter can be any identifier and it's used to validate the token source later in the `ValidateToken` function. It can be an email, user ID, form name (for CSRF tokens), etc.
func DecryptFromString ¶
DecryptFromString decrypts a string with a key
func EncryptToString ¶
EncryptToString encrypts content with a key using AES256 and encodes it to a hexadecimal string
func PassphraseToKey ¶
PassphraseToKey converts a string to a key for encryption
func RandomString ¶
RandomString generates a random string of the specified length
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.