github.com/TeaOSLab/EdgeNode@v1.3.8/internal/encrypt/method_aes_128_cfb_test.go (about) 1 package encrypt 2 3 import ( 4 "runtime" 5 "strings" 6 "testing" 7 ) 8 9 func TestAES128CFBMethod_Encrypt(t *testing.T) { 10 method, err := NewMethodInstance("aes-128-cfb", "abc", "123") 11 if err != nil { 12 t.Fatal(err) 13 } 14 src := []byte("Hello, World") 15 dst, err := method.Encrypt(src) 16 if err != nil { 17 t.Fatal(err) 18 } 19 dst = dst[:len(src)] 20 t.Log("dst:", string(dst)) 21 22 src, err = method.Decrypt(dst) 23 if err != nil { 24 t.Fatal(err) 25 } 26 t.Log("src:", string(src)) 27 } 28 29 func TestAES128CFBMethod_Encrypt2(t *testing.T) { 30 method, err := NewMethodInstance("aes-128-cfb", "abc", "123") 31 if err != nil { 32 t.Fatal(err) 33 } 34 35 sources := [][]byte{} 36 37 { 38 a := []byte{1} 39 _, err = method.Encrypt(a) 40 if err != nil { 41 t.Fatal(err) 42 } 43 } 44 45 for i := 0; i < 10; i++ { 46 src := []byte(strings.Repeat("Hello", 1)) 47 dst, err := method.Encrypt(src) 48 if err != nil { 49 t.Fatal(err) 50 } 51 52 sources = append(sources, dst) 53 } 54 55 { 56 a := []byte{1} 57 _, err = method.Decrypt(a) 58 if err != nil { 59 t.Fatal(err) 60 } 61 } 62 63 for _, dst := range sources { 64 dst2 := append([]byte{}, dst...) 65 src2, err := method.Decrypt(dst2) 66 if err != nil { 67 t.Fatal(err) 68 } 69 t.Log(string(src2)) 70 } 71 } 72 73 func BenchmarkAES128CFBMethod_Encrypt(b *testing.B) { 74 runtime.GOMAXPROCS(1) 75 76 method, err := NewMethodInstance("aes-128-cfb", "abc", "123") 77 if err != nil { 78 b.Fatal(err) 79 } 80 81 src := []byte(strings.Repeat("Hello", 1024)) 82 for i := 0; i < b.N; i++ { 83 dst, err := method.Encrypt(src) 84 if err != nil { 85 b.Fatal(err) 86 } 87 _ = dst 88 } 89 }