Skip to content

Commit 5560a01

Browse files
committed
add md5 and sha1
1 parent f0d9706 commit 5560a01

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Utils for golang
88

99
+ redisutil
1010
+ dbutil
11+
+ cryptoutil
1112

1213
#### v0.2.0
1314

utils/cryptoutil/CryptoUtil.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ import (
44
"bytes"
55
"crypto/aes"
66
"crypto/cipher"
7+
"crypto/md5"
8+
"crypto/sha1"
79
"encoding/base64"
10+
"fmt"
811
"github.com/jumpingcoder/quickutil4go/utils/logutil"
912
"strings"
1013
)
@@ -21,6 +24,16 @@ func Base64Decrypt(content string) []byte {
2124
return output
2225
}
2326

27+
func MD5Encrypt(content []byte) string {
28+
sum := md5.Sum(content)
29+
return fmt.Sprintf("%x", sum)
30+
}
31+
32+
func SHA1Encrypt(content []byte) string {
33+
sum := sha1.Sum(content)
34+
return fmt.Sprintf("%x", sum)
35+
}
36+
2437
func AESCBCEncrypt(content []byte, key []byte, iv []byte) []byte {
2538
block, err := aes.NewCipher(key)
2639
if err != nil {

utils/cryptoutil/CryptoUtil_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,7 @@ func TestEncryptConfigHandler(t *testing.T) {
1111
func TestDecryptConfigHandler(t *testing.T) {
1212
t.Log(DecryptConfigHandler("ENC(ozPh7o7XOvEup69IjSAbOg==)", "0000000011111111"))
1313
}
14+
15+
func TestMD5Encrypt(t *testing.T) {
16+
t.Log(MD5Encrypt([]byte("123456")))
17+
}

0 commit comments

Comments
 (0)