|
@@ -10,9 +10,18 @@ import (
|
|
"encoding/base64"
|
|
"encoding/base64"
|
|
"encoding/hex"
|
|
"encoding/hex"
|
|
"fmt"
|
|
"fmt"
|
|
|
|
+ "git.sxidc.com/go-tools/utils/strutils"
|
|
)
|
|
)
|
|
|
|
|
|
func AESEncrypt(originData string, key string) (string, error) {
|
|
func AESEncrypt(originData string, key string) (string, error) {
|
|
|
|
+ if strutils.IsStringEmpty(originData) {
|
|
|
|
+ return "", nil
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if strutils.IsStringEmpty(key) {
|
|
|
|
+ return originData, nil
|
|
|
|
+ }
|
|
|
|
+
|
|
keyBytes := []byte(key)
|
|
keyBytes := []byte(key)
|
|
|
|
|
|
block, err := aes.NewCipher(keyBytes)
|
|
block, err := aes.NewCipher(keyBytes)
|
|
@@ -31,6 +40,14 @@ func AESEncrypt(originData string, key string) (string, error) {
|
|
}
|
|
}
|
|
|
|
|
|
func AESDecrypt(encrypted string, key string) (string, error) {
|
|
func AESDecrypt(encrypted string, key string) (string, error) {
|
|
|
|
+ if strutils.IsStringEmpty(encrypted) {
|
|
|
|
+ return "", nil
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if strutils.IsStringEmpty(key) {
|
|
|
|
+ return encrypted, nil
|
|
|
|
+ }
|
|
|
|
+
|
|
keyBytes := []byte(key)
|
|
keyBytes := []byte(key)
|
|
|
|
|
|
block, err := aes.NewCipher(keyBytes)
|
|
block, err := aes.NewCipher(keyBytes)
|