添加md5流式计算
This commit is contained in:
+1
-1
@@ -144,7 +144,7 @@ func AESGCMEncrypt(key, plaintext string) (ciphertext, noncetext string, err err
|
||||
}
|
||||
|
||||
/*
|
||||
AES CBC 解码
|
||||
AES GCM 解码
|
||||
key:解密key
|
||||
ciphertext:加密返回的串
|
||||
plaintext:解密后的字符串
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
+9
-1
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user