Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func InputPassword ¶
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 ¶
KeyFromPassword creates a 32-byte encryption key from the given password. This is the symmetric encryption key for use with NewEncryption().
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).