package main
import (
"encoding/base64"
"fmt"
)
func main() {
strA := "123"
strB := fmt.Sprintf("Admin%s", strA)
//base64编码
encryText := base64.StdEncoding.EncodeToString([]byte(strB))
fmt.Println("base64编码:" + encryText)
//base64解码
decryText, err := base64.StdEncoding.DecodeString(encryText)
if err != nil {
fmt.Println("Error: ", err)
return
}
fmt.Println("base64解码:" + string(decryText))
userName := "Admin123"
//base64编码
strBase64_encry := base64.StdEncoding.EncodeToString([]byte(userName))
//XOR加密
xorEncryTxt := XorEncry_Decry(strBase64_encry, 'w')
fmt.Println("XOR加密:" + xorEncryTxt)
//XOR解密
xorDecryTxt := XorEncry_Decry(xorEncryTxt, 'w')
//base64解码
strBase64_decry, err := base64.StdEncoding.DecodeString(xorDecryTxt)
if err != nil {
fmt.Println("Error: ", err)
return
}
strBase64_decry_str := string(strBase64_decry)
fmt.Println("XOR解密:" + strBase64_decry_str)
fmt.Println("---------------------")
encryStr := XorEncryStr("Admin123", 'w')
fmt.Println("异或加密:" + encryStr)
decryStr := XorDecryStr(encryStr, 'w')
fmt.Println("异或解密:" + decryStr)
}
func XorEncry_Decry(str string, key byte) string {
var text string
for i := 0; i < len(str); i++ {
text += string(str[i] ^ key)
}
return text
}
/*--------XOR加密、key秘钥-------*/
func XorEncryStr(str string, key byte) string {
//base64编码
strBase64_encry := base64.StdEncoding.EncodeToString([]byte(str))
var text string
for i := 0; i < len(strBase64_encry); i++ {
text += string(strBase64_encry[i] ^ key)
}
return text
}
/*--------XOR解密、key秘钥-------*/
func XorDecryStr(str string, key byte) string {
var text string
for i := 0; i < len(str); i++ {
text += string(str[i] ^ key)
}
//base64解码
strBase64_decry, err := base64.StdEncoding.DecodeString(text)
if err != nil {
fmt.Println("Error: ", err)
return ""
}
return string(strBase64_decry)
}