|
|
@@ -4,7 +4,10 @@ import (
|
|
|
"bytes"
|
|
|
"crypto/aes"
|
|
|
"crypto/cipher"
|
|
|
+ "crypto/md5"
|
|
|
+ "crypto/sha256"
|
|
|
"encoding/base64"
|
|
|
+ "fmt"
|
|
|
)
|
|
|
|
|
|
func AESEncrypt(originData string, key string) (string, error) {
|
|
|
@@ -47,6 +50,14 @@ func AESDecrypt(encrypted string, key string) (string, error) {
|
|
|
return string(originData), nil
|
|
|
}
|
|
|
|
|
|
+func MD5(origin string) string {
|
|
|
+ return fmt.Sprintf("%x", md5.New().Sum([]byte(origin)))
|
|
|
+}
|
|
|
+
|
|
|
+func SHA256(origin string) string {
|
|
|
+ return fmt.Sprintf("%x", sha256.Sum256([]byte(origin)))
|
|
|
+}
|
|
|
+
|
|
|
func pkcs7Padding(ciphertext []byte, blockSize int) []byte {
|
|
|
padding := blockSize - len(ciphertext)%blockSize
|
|
|
padText := bytes.Repeat([]byte{byte(padding)}, padding)
|