Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInvalidHeader is returned when the header is too short. ErrInvalidHeader = errors.New("invalid sbox header") // ErrInvalidMagic is returned is the header does not start with magic // prefix. ErrInvalidMagic = errors.New("invalid magic") // ErrCouldNotDecrypt is returned when the secret box decryption fails. ErrCouldNotDecrypt = errors.New("could not decrypt") // ErrInvalidNonce is returned when a user provided nonce is of an // invalid size. A user provided nonce must be 0 < N <= 24. ErrInvalidNonce = errors.New("invalid nonce size") )
Functions ¶
func Decrypt ¶
Decrypt decrypts the packed blob using provided key. It unpacks the sbox header and returns the version and unencrypted data if successful.
func Encrypt ¶
Encrypt encrypts data with the provided key and generates a random nonce. Note that it is the callers responsibility to ensure that a nonce is NEVER reused with the same key. It prefixes the encrypted blob with an sbox header which encodes the provided version. The user provided version can be used as a hint to identify or version the packed blob. Version is not inspected or used by Encrypt and Decrypt.
func EncryptN ¶ added in v1.1.0
EncryptN encrypts data with the provided key and nonce. Note that it is the callers responsibility to ensure that a nonce is NEVER reused with the same key. It prefixes the encrypted blob with an sbox header which encodes the provided version. The user provided version can be used as a hint to identify or version the packed blob. Version is not inspected or used by Encrypt and Decrypt.
Types ¶
type Nonce ¶ added in v1.1.0
Nonce represents a valid nonce and counter that can be used as an input to EncryptN. Note that the caller is responsible for ensuring that a nonce is never reused with the same key.
func NewNonceFromBytes ¶ added in v1.1.0
NewNonceFromBytes returns a nonce that is set to n.