From 8b8575566bea063298d3b7fd2bdadc745bbe0ec5 Mon Sep 17 00:00:00 2001 From: Yun Date: Fri, 15 Mar 2024 13:49:58 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0md5=E6=B5=81=E5=BC=8F?= =?UTF-8?q?=E8=AE=A1=E7=AE=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- aesx/aesx.go | 2 +- aesx/aesx_test.go | 11 +++++++++++ md5x/md5x.go | 10 +++++++++- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/aesx/aesx.go b/aesx/aesx.go index ac08b94..97dd21a 100644 --- a/aesx/aesx.go +++ b/aesx/aesx.go @@ -144,7 +144,7 @@ func AESGCMEncrypt(key, plaintext string) (ciphertext, noncetext string, err err } /* -AES CBC 解码 +AES GCM 解码 key:解密key ciphertext:加密返回的串 plaintext:解密后的字符串 diff --git a/aesx/aesx_test.go b/aesx/aesx_test.go index a5bd5f1..b850083 100644 --- a/aesx/aesx_test.go +++ b/aesx/aesx_test.go @@ -10,6 +10,10 @@ import ( func TestAes(t *testing.T) { key := "example key 1234" plaintext := "exampleplaintext" + + // aesx.AesEncrypt(plaintext,key) + // aesx.AesDecrypt() + ciphertext, err := aesx.AESCBCEncrypt(key, plaintext) fmt.Println(ciphertext, err) @@ -23,3 +27,10 @@ func TestAes(t *testing.T) { plaintext, err = aesx.AESGCMDecrypter(key, ciphertext, noncetext) fmt.Println(plaintext, err) } + +func TestDemo(t *testing.T) { + c := []byte("08I2GfoqfIlUYgteelimxQ") + c := []byte("rRq++jXDMPDVcUkXAZA9kg==:o57DgQ+iQMXpERuShWs/XA==") + a,e := aesx.AesDecrypt(c, k) + fmt.Println(a,e) +} diff --git a/md5x/md5x.go b/md5x/md5x.go index 355e2e9..16e480b 100644 --- a/md5x/md5x.go +++ b/md5x/md5x.go @@ -22,7 +22,15 @@ func Md5File(path string) (string, error) { } defer file.Close() + return Md5Stream(file) +} + +// 流式的md5 +func Md5Stream(reader io.Reader) (string, error) { hash := md5.New() - io.Copy(hash, file) + _, err := io.Copy(hash, reader) + if err != nil { + return "", err + } return hex.EncodeToString(hash.Sum(nil)), nil }