encrypt-aes_test.go 465 B

123456789101112131415161718192021222324
  1. package util
  2. import (
  3. "bytes"
  4. "testing"
  5. )
  6. // TestAES test
  7. func TestAES(t *testing.T) {
  8. var bb bytes.Buffer
  9. for bb.Len() < 1024 {
  10. bb.Write([]byte("this is a very long text. "))
  11. }
  12. b := bb.Bytes()
  13. t.Logf("DATA %v %s", len(b), string(b))
  14. key := KeyAES()
  15. x := EncryptAES(key, b)
  16. t.Logf("ENC LEN %v", len(x))
  17. p := DecryptAES(key, x)
  18. t.Logf("PLAIN %v %s", len(p), string(p))
  19. if !bytes.Equal(b, p) {
  20. t.Errorf("ERROR\n%s\n%s", string(b), string(p))
  21. }
  22. }