decrypts the ciphertext using AES-GCM with the given key and returns the plaintext
(ciphertext, key []byte)
| 4050 | |
| 4051 | // decrypts the ciphertext using AES-GCM with the given key and returns the plaintext |
| 4052 | func decrypt(ciphertext, key []byte) ([]byte, error) { |
| 4053 | block, err := aes.NewCipher(key) |
| 4054 | if err != nil { |
| 4055 | return nil, err |
| 4056 | } |
| 4057 | |
| 4058 | aesGCM, err := cipher.NewGCM(block) |
| 4059 | if err != nil { |
| 4060 | return nil, err |
| 4061 | } |
| 4062 | |
| 4063 | nonceSize := aesGCM.NonceSize() |
| 4064 | if len(ciphertext) < nonceSize { |
| 4065 | return nil, errors.New("ciphertext too short") |
| 4066 | } |
| 4067 | |
| 4068 | nonce, ciphertext := ciphertext[:nonceSize], ciphertext[nonceSize:] |
| 4069 | d, err := aesGCM.Open(nil, nonce, ciphertext, nil) |
| 4070 | if err != nil { |
| 4071 | return nil, err |
| 4072 | } |
| 4073 | return d, nil |
| 4074 | } |
| 4075 | |
| 4076 | // validateAttributes validates keys and values of an attributes map, handling nil input |
| 4077 | func (c *connection) validateAttributes(attributes map[string]any) (map[string]any, error) { |