func (a *AESGCMCipher) Encrypt(data []byte, key Key) ([]byte, error) {
	aesKey, ok := key.(*AESKey)
	if !ok {
		return nil, fmt.Errorf("key must be of *AESKey, but was %T", key)
	}

	gcm, err := newBlockCipher(aesKey, a.nonceSizeBytes)
	if err != nil {
		return nil, err
	}

	// generate random nonce/IV
	nonce, err := RandomBytes(gcm.NonceSize())
	if err != nil {
		return nil, fmt.Errorf("failed to generate nonce: %v", err)
	}

	encrypted := gcm.Seal(nil, nonce, data, nil)

	return append(nonce, encrypted...), nil
}
// Encrypt encrypts the provided value using the specified key. The key must be of type *AESKey. The returned bytes are
// [nonce+ciphertext+tag].
Encrypt encrypts the provided value using the specified key. The key must be of type *AESKey. The returned bytes are
[nonce+ciphertext+tag].
// Encrypt encrypts the provided value using the specified key . The key must be of type * AESKey . The returned bytes are // [ nonce + ciphertext + tag ] .
func (a *AESGCMCipher) Encrypt(data []byte, key Key) ([]byte, error) {
	aesKey, ok := key.(*AESKey)
	if !ok {
		return nil, fmt.Errorf("key must be of *AESKey, but was %T", key)
	}
	gcm, err := newBlockCipher(aesKey, a.nonceSizeBytes)
	if err != nil {
		return nil, err
	}
	nonce, err := RandomBytes(gcm.NonceSize())
	if err != nil {
		return nil, fmt.Errorf("failed to generate nonce: %v", err)
	}
	encrypted := gcm.Seal(nil, nonce, data, nil)
	return append(nonce, encrypted...), nil
}
func ( a * AESGCMCipher ) Encrypt ( data [ ] byte , key Key ) ( [ ] byte , error ) { aesKey , ok := key . ( * AESKey ) if ! ok { return nil , fmt . Errorf ( " " , key ) } gcm , err := newBlockCipher ( aesKey , a . nonceSizeBytes ) if err != nil { return nil , err } nonce , err := RandomBytes ( gcm . NonceSize ( ) ) if err != nil { return nil , fmt . Errorf ( " " , err ) } encrypted := gcm . Seal ( nil , nonce , data , nil ) return append ( nonce , encrypted ... ) , nil }
Encrypt encrypts the provided value using the specified key.
Encrypt encrypts the provided value using the specified key .
// generate random nonce/IV