github.com/tickstep/library-go@v0.1.1/crypto/aes_test.go (about) 1 package crypto 2 3 import ( 4 "encoding/hex" 5 "fmt" 6 "github.com/stretchr/testify/assert" 7 "testing" 8 ) 9 10 func TestEncrypt(t *testing.T) { 11 d := []byte("131687xxxxx@189.cn") 12 key := []byte("16384aeed126e11b74a1f99b91da91814c56a588fe6bf11f92946c0e3a400f5f")[:16] 13 fmt.Println(len(key)) 14 r, e := EncryptAES(d, key) 15 if e != nil { 16 fmt.Println(e) 17 return 18 } 19 fmt.Printf("%+v", hex.EncodeToString(r)) 20 assert.Equal(t, "f13cae8f25083526db1b14a148d8822ea94e65ff2785b99f9e69a835bebdf6ee", hex.EncodeToString(r)) 21 } 22 23 func TestDecrypt(t *testing.T) { 24 d, _ := hex.DecodeString("f13cae8f25083526db1b14a148d8822ea94e65ff2785b99f9e69a835bebdf6ee") 25 key := []byte("16384aeed126e11b74a1f99b91da91814c56a588fe6bf11f92946c0e3a400f5f")[:16] 26 r, e := DecryptAES(d, key) 27 if e != nil { 28 fmt.Println(e) 29 return 30 } 31 fmt.Printf("%s", string(r)) 32 assert.Equal(t, "131687xxxxx@189.cn", string(r)) 33 }