正在显示
2 个修改的文件
包含
50 行增加
和
2 行删除
fastEncryptDecode/endecode_test.go
0 → 100644
| 1 | +package fastEncryptDecode | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "encoding/base64" | ||
| 5 | + "testing" | ||
| 6 | +) | ||
| 7 | + | ||
| 8 | +func TestMD5hash(T *testing.T) { | ||
| 9 | + str := "123456" | ||
| 10 | + md := MD5hash([]byte(str)) | ||
| 11 | + T.Log("str", str) | ||
| 12 | + T.Log("str MD5 ", md) | ||
| 13 | + ok := MD5Verify(str, md) | ||
| 14 | + if !ok { | ||
| 15 | + T.Error("MD5Verify err") | ||
| 16 | + } | ||
| 17 | +} | ||
| 18 | + | ||
| 19 | +const ( | ||
| 20 | + plantText string = "tangxvhuitangxvhui" //加密前 | ||
| 21 | + aesKey string = "1234567890123456" //密钥 | ||
| 22 | + base64String string = "imeIhfwP+X+a9f3Mh3jOUgmkhBtrobb0vXubnyDg/3s=" //加密后 | ||
| 23 | +) | ||
| 24 | + | ||
| 25 | +func TestAesEncryptCBC(T *testing.T) { | ||
| 26 | + btString, err := AesEncryptCBC([]byte(plantText), []byte(aesKey)) | ||
| 27 | + if err != nil { | ||
| 28 | + T.Error(err) | ||
| 29 | + } | ||
| 30 | + base64String := base64.StdEncoding.EncodeToString(btString) | ||
| 31 | + T.Log("base64:=", base64String) | ||
| 32 | +} | ||
| 33 | + | ||
| 34 | +func TestAesDecryptCBC(T *testing.T) { | ||
| 35 | + btstring, err := base64.StdEncoding.DecodeString(base64String) | ||
| 36 | + if err != nil { | ||
| 37 | + T.Error("base64 err", err) | ||
| 38 | + } | ||
| 39 | + btString, err := AesDecryptCBC([]byte(btstring), []byte(aesKey)) | ||
| 40 | + if err != nil { | ||
| 41 | + T.Error(err) | ||
| 42 | + } | ||
| 43 | + | ||
| 44 | + if plantText != string(btString) { | ||
| 45 | + T.Error("AesDecryptCBC err ") | ||
| 46 | + } | ||
| 47 | + | ||
| 48 | +} |
| @@ -65,8 +65,8 @@ func AesDecryptCBC(cipherText, key []byte) ([]byte, error) { | @@ -65,8 +65,8 @@ func AesDecryptCBC(cipherText, key []byte) ([]byte, error) { | ||
| 65 | if err != nil { | 65 | if err != nil { |
| 66 | return nil, err | 66 | return nil, err |
| 67 | } | 67 | } |
| 68 | - keyBytes := []byte(key) | ||
| 69 | - block, err := aes.NewCipher(keyBytes) | 68 | + |
| 69 | + block, err := aes.NewCipher(key) | ||
| 70 | if err != nil { | 70 | if err != nil { |
| 71 | return nil, err | 71 | return nil, err |
| 72 | } | 72 | } |
-
请 注册 或 登录 后发表评论