(data []byte, key []byte)
| 7 | ) |
| 8 | |
| 9 | func AESGCMEncrypt(data []byte, key []byte) ([]byte, error) { |
| 10 | nonce := make([]byte, 12) |
| 11 | if _, err := rand.Read(nonce); err != nil { |
| 12 | return nil, err |
| 13 | } |
| 14 | |
| 15 | block, err := aes.NewCipher(key) |
| 16 | if err != nil { |
| 17 | return nil, err |
| 18 | } |
| 19 | aead, err := cipher.NewGCM(block) |
| 20 | if err != nil { |
| 21 | return nil, err |
| 22 | } |
| 23 | ciphertext := aead.Seal(nil, nonce, data, nil) |
| 24 | |
| 25 | result := make([]byte, len(nonce)+len(ciphertext)) |
| 26 | copy(result[:len(nonce)], nonce) |
| 27 | copy(result[len(nonce):], ciphertext) |
| 28 | |
| 29 | return result, nil |
| 30 | } |
| 31 | |
| 32 | func AESGCMDecrypt(data []byte, key []byte) ([]byte, error) { |
| 33 | nonce := data[:12] |
no outgoing calls
no test coverage detected