Documentation
¶
Index ¶
- type Crypter
- func NewAESGCM(key []byte, nonceGenerator NonceGenerator) (*Crypter, error)
- func NewAESGCMWithRandomNonceGenerator(key []byte) (*Crypter, error)
- func NewChaCha20Poly1305(key []byte, nonceGenerator NonceGenerator) (*Crypter, error)
- func NewChaCha20Poly1305WithRandomNonceGenerator(key []byte) (*Crypter, error)
- func NewCrypter(aead cipher.AEAD, kind string, nonceGenerator NonceGenerator) *Crypter
- type NonceGenerator
- type RandomNonceGenerator
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Crypter ¶
type Crypter struct {
// contains filtered or unexported fields
}
Crypter contains the AEAD cipher to use for encryption and decryption.
func NewAESGCM ¶
func NewAESGCM(key []byte, nonceGenerator NonceGenerator) (*Crypter, error)
NewAESGCM creates a new Cryptor initialised with an AES-GCM cipher from the supplied key. The key is sensitive, never share it openly.
The key should be 16 bytes (AES-128) or 32 bytes (AES-256) long.
If you want to convert a passphrase to a key, use a suitable package like bcrypt or scrypt.
TODO: add a nonceGenerator validator i.e. call it 1000 times, ensures no dupes.
func NewAESGCMWithRandomNonceGenerator ¶
NewAESGCMWithRandomNonceGenerator creates a new Cryptor initialised with an AES-GCM cipher from the supplied key and the default nonce generator.
func NewChaCha20Poly1305 ¶
func NewChaCha20Poly1305(key []byte, nonceGenerator NonceGenerator) (*Crypter, error)
NewChaCha20Poly1305 creates a new Cryptor initialised with a ChaCha20Poly1305 cipher from the supplied key. The key is sensitive, never share it openly.
The key should be 32 bytes long.
If you want to convert a passphrase to a key, you can use a function such as Argon2.
TODO: add a nonceGenerator validator i.e. call it 1000 times, ensures no dupes.
func NewChaCha20Poly1305WithRandomNonceGenerator ¶
NewChaCha20Poly1305WithRandomNonceGenerator creates a new Cryptor initialised with a ChaCha20Poly1305 cipher from the supplied key and the default nonce generator.
func NewCrypter ¶
func NewCrypter(aead cipher.AEAD, kind string, nonceGenerator NonceGenerator) *Crypter
NewCrypter creates a new initialised Crypter.
func (Crypter) Decrypt ¶
Decrypt performs the decryption of the provided ciphertext with the key associated with this Crypter and the supplied nonce. This must be the same nonce that was used to encrypt the ciphertext. The nonce is not sensitive.
type NonceGenerator ¶
NonceGenerator defines the behaviour of a Nonce Generator type.
type RandomNonceGenerator ¶
type RandomNonceGenerator struct {
// contains filtered or unexported fields
}
RandomNonceGenerator is a random generator of nonce of the specified size.
func NewRandomNonceGenerator ¶
func NewRandomNonceGenerator(size int) *RandomNonceGenerator
NewRandomNonceGenerator creates a new initialised RandomNonceGenerator of specified size.
func (RandomNonceGenerator) Generate ¶
func (ng RandomNonceGenerator) Generate() ([]byte, error)
For a 12-byte nonce, never use more than 2^32 random nonces with a given key because of the risk of a repeat and cipher .