Skip to content

Commit

Permalink
add md5 and sha1
Browse files Browse the repository at this point in the history
  • Loading branch information
jumpingcoder committed Jul 4, 2021
1 parent f0d9706 commit 5560a01
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Utils for golang

+ redisutil
+ dbutil
+ cryptoutil

#### v0.2.0

Expand Down
13 changes: 13 additions & 0 deletions utils/cryptoutil/CryptoUtil.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import (
"bytes"
"crypto/aes"
"crypto/cipher"
"crypto/md5"
"crypto/sha1"
"encoding/base64"
"fmt"
"github.com/jumpingcoder/quickutil4go/utils/logutil"
"strings"
)
Expand All @@ -21,6 +24,16 @@ func Base64Decrypt(content string) []byte {
return output
}

func MD5Encrypt(content []byte) string {
sum := md5.Sum(content)
return fmt.Sprintf("%x", sum)
}

func SHA1Encrypt(content []byte) string {
sum := sha1.Sum(content)
return fmt.Sprintf("%x", sum)
}

func AESCBCEncrypt(content []byte, key []byte, iv []byte) []byte {
block, err := aes.NewCipher(key)
if err != nil {
Expand Down
4 changes: 4 additions & 0 deletions utils/cryptoutil/CryptoUtil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@ func TestEncryptConfigHandler(t *testing.T) {
func TestDecryptConfigHandler(t *testing.T) {
t.Log(DecryptConfigHandler("ENC(ozPh7o7XOvEup69IjSAbOg==)", "0000000011111111"))
}

func TestMD5Encrypt(t *testing.T) {
t.Log(MD5Encrypt([]byte("123456")))
}

0 comments on commit 5560a01

Please sign in to comment.