mirror of
https://github.com/gogs/gogs.git
synced 2026-02-26 08:10:59 +01:00
Co-authored-by: JSS <jss@unknwon.dev> Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
31 lines
483 B
Go
31 lines
483 B
Go
package cryptox
|
|
|
|
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)
|
|
}
|