secure

package
v0.52.0 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decrypt

func Decrypt(ciphertext []byte, key *[32]byte) (plaintext []byte, err error)

Decrypt decrypts data using 256-bit AES-GCM. This both hides the content of the data and provides a check that it hasn't been altered. Expects input form nonce|ciphertext|tag where '|' indicates concatenation. Taken from https://github.com/gtank/cryptopasta/blob/master/encrypt.go

func Encrypt

func Encrypt(plaintext []byte, key *[32]byte) (ciphertext []byte, err error)

Encrypt encrypts data using 256-bit AES-GCM. This both hides the content of the data and provides a check that it hasn't been altered. Output takes the form nonce|ciphertext|tag where '|' indicates concatenation. Taken from https://github.com/gtank/cryptopasta/blob/master/encrypt.go

func NewEncryptionKey

func NewEncryptionKey() (*[32]byte, error)

NewEncryptionKey generates a random 256-bit key. It will return an error if the system's secure random number generator fails to function correctly, in which case the caller should not continue. Taken from https://github.com/gtank/cryptopasta/blob/master/encrypt.go

func ParseEncryptionKey

func ParseEncryptionKey(s string) (*[32]byte, error)

ParseEncryptionKey decodes the string representation of an encryption key and returns its bytes

Types

type Identifier

type Identifier []byte

Identifier is a random, cryptographically generated sequence of characters used to refer to something

func MustParseIdentifier

func MustParseIdentifier(s string) Identifier

MustParseIdentifier is like Parse but panics if the string cannot be parsed.

func NewID

func NewID() Identifier

NewID is like NewIdentifier, but panics if the Identifier cannot be initialized

func NewIdentifier

func NewIdentifier(n int) (Identifier, error)

NewIdentifier creates a new random Identifier of n bytes or returns an error.

func ParseIdentifier

func ParseIdentifier(s string) (Identifier, error)

ParseIdentifier decodes s into Identifier or returns an error.

func (Identifier) String

func (e Identifier) String() string

String returns the string form of Identifier (base64 encoded according to RFC 4648).

type RandomGenerator

type RandomGenerator struct{}

RandomGenerator produces cryptographically secure random data

func (RandomGenerator) RandomBytes

func (g RandomGenerator) RandomBytes(n int) ([]byte, error)

RandomBytes returns securely generated random bytes. It will return an error if the system's secure random number generator fails to function correctly, in which case the caller should not continue. Taken from https://stackoverflow.com/questions/35781197/generating-a-random-fixed-length-byte-array-in-go

func (RandomGenerator) RandomString

func (g RandomGenerator) RandomString(n int) (string, error)

RandomString returns a URL-safe, base64 encoded, securely generated, random string. It will return an error if the system's secure random number generator fails to function correctly, in which case the caller should not continue. This should be used when there are concerns about security and need something cryptographically secure.

Jump to

Keyboard shortcuts

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