GenerateKey generates a new AES key and returns it as a base64 encoded string
()
| 16 | |
| 17 | // GenerateKey generates a new AES key and returns it as a base64 encoded string |
| 18 | func GenerateKey() (string, error) { |
| 19 | key := make([]byte, 32) // AES-256 |
| 20 | if _, err := io.ReadFull(rand.Reader, key); err != nil { |
| 21 | return "", err |
| 22 | } |
| 23 | return base64.StdEncoding.EncodeToString(key), nil |
| 24 | } |
| 25 | |
| 26 | // Encrypt encrypts the given plaintext using AES-GCM with the provided base64 encoded key and returns the ciphertext as a base64 encoded string |
| 27 | func Encrypt(plaintext, base64Key string) (string, error) { |