mirror of
https://github.com/gogs/gogs.git
synced 2026-02-28 09:10:57 +01:00
Co-authored-by: deepsource-autofix[bot] <62050782+deepsource-autofix[bot]@users.noreply.github.com>
31 lines
486 B
Go
31 lines
486 B
Go
package cryptoutil
|
|
|
|
import (
|
|
"crypto/rand"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestAESGCM(t *testing.T) {
|
|
key := make([]byte, 16) // AES-128
|
|
_, err := rand.Read(key)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
plaintext := []byte("this will be encrypted")
|
|
|
|
encrypted, err := AESGCMEncrypt(key, plaintext)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
decrypted, err := AESGCMDecrypt(key, encrypted)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
assert.Equal(t, plaintext, decrypted)
|
|
}
|