f
This commit is contained in:
@@ -4,9 +4,11 @@ import (
|
||||
"bytes"
|
||||
"crypto/aes"
|
||||
"crypto/cipher"
|
||||
"crypto/md5"
|
||||
"encoding/base64"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"io"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -119,3 +121,10 @@ func pkcs7Unpadding(src []byte) ([]byte, error) {
|
||||
|
||||
return src[:length-unpadding], nil
|
||||
}
|
||||
|
||||
// MD5 使用MD5加密数据,返回十六进制字符串
|
||||
func MD5(data string) string {
|
||||
h := md5.New()
|
||||
io.WriteString(h, data)
|
||||
return hex.EncodeToString(h.Sum(nil))
|
||||
}
|
||||
|
||||
@@ -315,6 +315,12 @@ func (z *ZhichaService) Decrypt(encryptedData string) (string, error) {
|
||||
return string(unpadded), nil
|
||||
}
|
||||
|
||||
// MD5 对字符串进行MD5加密并返回32位小写十六进制字符串
|
||||
func (z *ZhichaService) MD5(data string) string {
|
||||
hash := md5.Sum([]byte(data))
|
||||
return hex.EncodeToString(hash[:])
|
||||
}
|
||||
|
||||
// pkcs7Padding 使用PKCS7填充数据
|
||||
func (z *ZhichaService) pkcs7Padding(src []byte, blockSize int) []byte {
|
||||
padding := blockSize - len(src)%blockSize
|
||||
|
||||
Reference in New Issue
Block a user