security

package
v0.0.0-...-efd161f Latest Latest
Warning

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

Go to latest
Published: May 22, 2022 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InputPassword

func InputPassword(confirm bool) (string, error)

InputPassword displays a command-line prompt to enter a password without displaying the entered characters.

If 'confirm' is true, also prompts for a confirmation. If the password and confirmation don't match, returns a blank string and an error.

This function may not work if 'Stdin' is redirected, for example when running in debug mode in VS Code.

func KeyFromPassword

func KeyFromPassword(pwd string) []byte

KeyFromPassword creates a 32-byte encryption key from the given password. This is the symmetric encryption key for use with NewEncryption().

func MakeHash

func MakeHash(data []byte) [64]byte

MakeHash returns the SHA-512 hash of byte slice 'data'.

Types

type Encryption

type Encryption struct {
	// contains filtered or unexported fields
}

Encryption provides symmetric encryption and decryption using AES-256 as the encryption cipher.

Create a new Encryption with NewEncryption(key). You can then use the returned object to encrypt data with EncryptBytes() and decrypt with DecryptBytes().

func NewEncryption

func NewEncryption(key []byte) (*Encryption, error)

NewEncryption creates a new Encryption object initialized with the specified 'key' for encryption or decryption. The key must be exactly 32 bytes in length for AES-256 encryption which is used by Encryption.

func (*Encryption) DecryptBytes

func (enc *Encryption) DecryptBytes(ciphertext []byte) ([]byte, error)

DecryptBytes decrypts the specified ciphertext and returns its plaintext. If there was an error decrypting, returns nil and an error.

func (*Encryption) EncryptBytes

func (enc *Encryption) EncryptBytes(plaintext []byte) ([]byte, error)

EncryptBytes encrypts the specified plaintext and returns its ciphertext. If there was an error encrypting, returns nil and an error.

func (*Encryption) Validate

func (enc *Encryption) Validate() error

Validate checks if this Encryption object was initialized properly using NewEncryption(). The symmetric encryption key must be exactly 32 bytes in length (needed by AES-256).

Jump to

Keyboard shortcuts

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