diff --git a/README.md b/README.md index 8d382b5..84bff23 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,7 @@ Utils for golang + redisutil + dbutil ++ cryptoutil #### v0.2.0 diff --git a/utils/cryptoutil/CryptoUtil.go b/utils/cryptoutil/CryptoUtil.go index 0063fa8..ef33d5a 100644 --- a/utils/cryptoutil/CryptoUtil.go +++ b/utils/cryptoutil/CryptoUtil.go @@ -4,7 +4,10 @@ import ( "bytes" "crypto/aes" "crypto/cipher" + "crypto/md5" + "crypto/sha1" "encoding/base64" + "fmt" "github.com/jumpingcoder/quickutil4go/utils/logutil" "strings" ) @@ -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 { diff --git a/utils/cryptoutil/CryptoUtil_test.go b/utils/cryptoutil/CryptoUtil_test.go index 308ccbd..9e666d9 100644 --- a/utils/cryptoutil/CryptoUtil_test.go +++ b/utils/cryptoutil/CryptoUtil_test.go @@ -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"))) +}