2
0

aes_test.go 648 B

12345678910111213141516171819202122232425262728293031323334
  1. // Copyright 2020 The Gogs Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package cryptoutil
  5. import (
  6. "crypto/rand"
  7. "testing"
  8. "github.com/stretchr/testify/assert"
  9. )
  10. func TestAESGCM(t *testing.T) {
  11. key := make([]byte, 16) // AES-128
  12. _, err := rand.Read(key)
  13. if err != nil {
  14. t.Fatal(err)
  15. }
  16. plaintext := []byte("this will be encrypted")
  17. encrypted, err := AESGCMEncrypt(key, plaintext)
  18. if err != nil {
  19. t.Fatal(err)
  20. }
  21. decrypted, err := AESGCMDecrypt(key, encrypted)
  22. if err != nil {
  23. t.Fatal(err)
  24. }
  25. assert.Equal(t, plaintext, decrypted)
  26. }