|
@@ -1,5 +1,6 @@
|
|
package services
|
|
package services
|
|
|
|
|
|
|
|
+// 加密解密
|
|
import (
|
|
import (
|
|
"crypto/aes"
|
|
"crypto/aes"
|
|
"crypto/cipher"
|
|
"crypto/cipher"
|
|
@@ -12,25 +13,71 @@ import (
|
|
|
|
|
|
var aseKey = []byte("kmk6ln3n4mibig8p") // 加密密钥(必须是16、24或32字节)
|
|
var aseKey = []byte("kmk6ln3n4mibig8p") // 加密密钥(必须是16、24或32字节)
|
|
|
|
|
|
-func init() {
|
|
|
|
|
|
+// 加密
|
|
|
|
+func AseEncrypted(originalData int) (encryptedData string, err error) {
|
|
// 原始数据
|
|
// 原始数据
|
|
- originalData := 123
|
|
|
|
-
|
|
|
|
|
|
+ //originalData := 123
|
|
// 加密数据
|
|
// 加密数据
|
|
- encryptedData, err := encrypt(originalData, aseKey)
|
|
|
|
- if err != nil {
|
|
|
|
- fmt.Println("加密时出错:", err)
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
- fmt.Println("加密后的数据:", encryptedData)
|
|
|
|
|
|
+ encryptedData, err = encrypt(originalData, aseKey)
|
|
|
|
+ //fmt.Println("加密后的数据:", encryptedData)
|
|
|
|
|
|
// 解密数据
|
|
// 解密数据
|
|
- decryptedData, err := decrypt(encryptedData, aseKey)
|
|
|
|
- if err != nil {
|
|
|
|
- fmt.Println("解密时出错:", err)
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
- fmt.Println("解密后的数据:", decryptedData)
|
|
|
|
|
|
+ //decryptedData, err := decrypt(encryptedData, aseKey)
|
|
|
|
+ //if err != nil {
|
|
|
|
+ // fmt.Println("解密时出错:", err)
|
|
|
|
+ // return
|
|
|
|
+ //}
|
|
|
|
+ //fmt.Println("解密后的数据:", decryptedData)
|
|
|
|
+ return
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// 加密
|
|
|
|
+//func AseDecrypted(encryptedData string) (originalData int, err error) {
|
|
|
|
+// // 原始数据
|
|
|
|
+// //originalData := 123
|
|
|
|
+// // 加密数据
|
|
|
|
+// encryptedData, err = encrypt(originalData, aseKey)
|
|
|
|
+// //fmt.Println("加密后的数据:", encryptedData)
|
|
|
|
+//
|
|
|
|
+// // 解密数据
|
|
|
|
+// //decryptedData, err := decrypt(encryptedData, aseKey)
|
|
|
|
+// //if err != nil {
|
|
|
|
+// // fmt.Println("解密时出错:", err)
|
|
|
|
+// // return
|
|
|
|
+// //}
|
|
|
|
+// //fmt.Println("解密后的数据:", decryptedData)
|
|
|
|
+// return
|
|
|
|
+//}
|
|
|
|
+
|
|
|
|
+//func init() {
|
|
|
|
+// fmt.Println(AseEncrypted(106))
|
|
|
|
+// //fmt.Println(decrypt(" m+v/mObub3ygVZrXdv0pX7kjNQ==", aseKey))
|
|
|
|
+//
|
|
|
|
+// //decryptedData, err := decrypt("tIVURU5VYGSPVVFINXANpHQ2/w==", aseKey)
|
|
|
|
+// decryptedData, err := decrypt("folm8/VB3NwxTVeTParQrosrVw==", aseKey)
|
|
|
|
+// if err != nil {
|
|
|
|
+// fmt.Println("解密时出错:", err)
|
|
|
|
+// return
|
|
|
|
+// }
|
|
|
|
+// fmt.Println("解密后的数据:", decryptedData)
|
|
|
|
+//}
|
|
|
|
+
|
|
|
|
+// 加密
|
|
|
|
+func AseDecrypted(encryptedData string) (decryptedData int, err error) {
|
|
|
|
+ // 原始数据
|
|
|
|
+ //originalData := 123
|
|
|
|
+ // 加密数据
|
|
|
|
+ //originalData, err = decrypt(encryptedData, aseKey)
|
|
|
|
+ //fmt.Println("加密后的数据:", encryptedData)
|
|
|
|
+ //return
|
|
|
|
+ // 解密数据
|
|
|
|
+ decryptedData, err = decrypt(encryptedData, aseKey)
|
|
|
|
+ //if err != nil {
|
|
|
|
+ // fmt.Println("解密时出错:", err)
|
|
|
|
+ // return
|
|
|
|
+ //}
|
|
|
|
+ //fmt.Println("解密后的数据:", decryptedData)
|
|
|
|
+ return
|
|
}
|
|
}
|
|
|
|
|
|
func encrypt(data int, key []byte) (string, error) {
|
|
func encrypt(data int, key []byte) (string, error) {
|