aboutsummaryrefslogtreecommitdiff
path: root/internal/cryptoutil/aes_test.go
blob: 0e34bcb084e4fda1edb565177a19d0ea3f23354c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// Copyright 2020 The Gogs Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

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)
}