(plaintext []byte)
| 21 | } |
| 22 | |
| 23 | func (e *Encryption) Encrypt(plaintext []byte) ([]byte, error) { |
| 24 | block, err := aes.NewCipher(e.key) |
| 25 | if err != nil { |
| 26 | return nil, err |
| 27 | } |
| 28 | gcm, err := cipher.NewGCM(block) |
| 29 | if err != nil { |
| 30 | return nil, err |
| 31 | } |
| 32 | nonce := make([]byte, gcm.NonceSize()) |
| 33 | if _, err = io.ReadFull(rand.Reader, nonce); err != nil { |
| 34 | return nil, err |
| 35 | } |
| 36 | ciphertext := gcm.Seal(nonce, nonce, plaintext, nil) |
| 37 | return ciphertext, nil |
| 38 | } |
| 39 | |
| 40 | func (e *Encryption) Decrypt(ciphertext []byte) ([]byte, error) { |
| 41 | block, err := aes.NewCipher(e.key) |
no outgoing calls