in src/encryption/encrypter.go [95:117]
func (encrypter *Encrypter) Encrypt(log log.T, plainText []byte) (cipherText []byte, err error) {
var aesgcm cipher.AEAD
if aesgcm, err = getAEAD(encrypter.encryptionKey); err != nil {
err = fmt.Errorf("%v", err)
return
}
cipherText = make([]byte, nonceSize+len(plainText))
nonce := make([]byte, nonceSize)
if _, err = io.ReadFull(rand.Reader, nonce); err != nil {
err = fmt.Errorf("error when generating nonce for encryption, %v", err)
return
}
// Encrypt plain text using given key and newly generated nonce
cipherTextWithoutNonce := aesgcm.Seal(nil, nonce, plainText, nil)
// Append nonce to the beginning of the cipher text to be used while decrypting
cipherText = append(cipherText[:nonceSize], nonce...)
cipherText = append(cipherText[nonceSize:], cipherTextWithoutNonce...)
return cipherText, nil
}