github.com/sandwich-go/boost@v1.3.29/xcrypto/algorithm/aes/aes_test.go (about) 1 package aes 2 3 import ( 4 "crypto/rand" 5 "github.com/sandwich-go/boost/xcrypto/key/curve25519" 6 "github.com/sandwich-go/boost/xrand" 7 "testing" 8 9 . "github.com/smartystreets/goconvey/convey" 10 ) 11 12 func getTestFrames() [][]byte { 13 return [][]byte{ 14 nil, 15 []byte(""), 16 []byte("time.Duration,[]time.Duration,map[string]*Redis此类的非基础类型的slice或者map都需要辅助指明类型"), 17 []byte(xrand.String(100)), 18 } 19 } 20 21 func TestAes(t *testing.T) { 22 Convey("test aes encryption", t, func() { 23 sk, err := curve25519.GenerateSecretKey() 24 So(err, ShouldBeNil) 25 26 for _, frame := range getTestFrames() { 27 encryptBody, err0 := Encrypt(frame, sk) 28 So(err0, ShouldBeNil) 29 decryptDest, err1 := Decrypt(encryptBody, sk) 30 So(err1, ShouldBeNil) 31 So(decryptDest, ShouldResemble, frame) 32 } 33 }) 34 } 35 36 // 80294 ns/op 37 func BenchmarkCBCEncrypt(b *testing.B) { 38 sk, _ := curve25519.GenerateSecretKey() 39 source := make([]byte, 65535) 40 _, _ = rand.Read(source) 41 for i := 0; i < b.N; i++ { 42 _, _ = Encrypt(source, sk) 43 } 44 } 45 46 // 70017 ns/op 47 func BenchmarkCBCDecrypt(b *testing.B) { 48 sk, _ := curve25519.GenerateSecretKey() 49 source := make([]byte, 65535) 50 _, _ = rand.Read(source) 51 dest, _ := Encrypt(source, sk) 52 for i := 0; i < b.N; i++ { 53 _, _ = Decrypt(dest, sk) 54 } 55 }