crypt

package
v0.31.8 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decrypt

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

Decrypt will decrypt something created by Encrypt. If the data is not decryptable, either because it is corrupt, or the key changed, an error is returned. Otherwise, if there is a system failure, it will panic.

func Encrypt

func Encrypt(data []byte, key []byte) []byte

Encrypt will encrypt the data using AES-GCM and return the encrypted data. Use Decrypt to decrypt the data. key is recommended to be 16 bytes long, and will produce an AES-128 encryption using GCM which is currently considered secure. Note that this is due to our use of GCM. When using CBC, AES-256 is considered secure, but GCM is better and faster. Errors will panic, since they are caused by some kind of system-wide failure or a bad key size.

func GenerateRandomBase64String added in v0.19.0

func GenerateRandomBase64String(s int) (string, error)

GenerateRandomBase64String returns a base64 encoded securely generated random string. The given value is the length of the initial random bytes represented by the base64 string. The actual length of the string will be bigger.

func GenerateRandomBytes

func GenerateRandomBytes(n int) ([]byte, error)

GenerateRandomBytes returns securely generated random bytes. It will return an error if the system's secure random number generator fails to function correctly.

func SessionDecrypt

func SessionDecrypt(ctx context.Context, encryptedValue []byte) []byte

SessionDecrypt will decrypt a value that was encrypted by the SessionEncrypt. If there was a problem with the decryption process, the result will be nil.

func SessionDecryptAttributeValue

func SessionDecryptAttributeValue(ctx context.Context, encryptedValue string) string

SessionDecryptAttributeValue decrypts a value encrypted with SessionEncryptAttributeValue. If there was a problem, an empty string is returned.

func SessionDecryptUrlValue

func SessionDecryptUrlValue(ctx context.Context, encryptedValue string) string

SessionDecryptUrlValue decrypts the give value that was encrypted using SessionEncryptUrlValue. If there was a problem, an empty string is returned.

func SessionEncrypt

func SessionEncrypt(ctx context.Context, value []byte) []byte

SessionEncrypt encrypts the value so that as long as the session does not change, it can be decrypted using SessionDecrypt. This is useful for any time you might need to send something to the browser that would pose a security risk, like a database id, or a pagestate in a URL. The resulting value is a raw byte stream and is not suitable for sending to the browser. See the other utilities for helpers depending on where you are sending the data.

func SessionEncryptAttributeValue

func SessionEncryptAttributeValue(ctx context.Context, value string) string

SessionEncryptAttributeValue encrypts a value so that it can be used as a value in an html attribute. Decrypt this value with SessionDecryptAttributeValue. It uses the ascii85 encoding algorithm.

func SessionEncryptUrlValue

func SessionEncryptUrlValue(ctx context.Context, value string) string

SessionEncryptUrlValue encrypts a value such that the resulting text can be used as a value in a URL. Decrypt the value using SessionDecryptUrlValue

Types

This section is empty.

Jump to

Keyboard shortcuts

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