crypto

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2019 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// 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 Decrypt

func Decrypt(cipherText, key []byte) (decrypted []byte, err error)

Decrypt decrypts content with a key using AES256

func DecryptFromString

func DecryptFromString(cipherTextStr string, key []byte) (decrypted []byte, err error)

DecryptFromString decrypts a string with a key

func Encrypt

func Encrypt(plainText, key []byte) (encrypted []byte, err error)

Encrypt encrypts content with a key using AES256

func EncryptToString

func EncryptToString(plainText, key []byte) (string, error)

EncryptToString encrypts content with a key using AES256 and encodes it to a hexadecimal string

func GenerateRandomString

func GenerateRandomString(length int) (string, error)

GenerateRandomString generates a random string with a given length

func PassphraseToKey

func PassphraseToKey(passphrase string) (key []byte)

PassphraseToKey converts a string to a key for encryption.

This function must be used STRICTLY ONLY for generating an encryption key out of a passphrase. Please don't use this function for hashing user-provided values. It uses SHA2 for simplicity but it's slower. User-provided data should use SHA3 because of its better performance.

Types

This section is empty.

Jump to

Keyboard shortcuts

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