Base64加密,解密方法
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Encrypt_Base64 : MonoBehaviour
{
/// <summary>
/// Base64加密,解密方法
/// </summary>
/// <paramname="str">输入字符串内容</param>
/// <paramname="bol">true-加密,false-解密</param>
public static string ReturnBase64(string str, bool bol)
{
if (bol)
{
return System.Convert.ToBase64String(System.Text.Encoding.Default.GetBytes(str));
}
else
{
try
{
return System.Text.Encoding.Default.GetString(System.Convert.FromBase64String(str));
}
catch (Exception exp)
{
return exp.Message;
}
}
}
// void Update()
// {
// if (Input.GetKeyDown(KeyCode.P))
// {
// Debug.Log("加密:" + ReturnBase64("123456789", true));
// }
// if (Input.GetKeyDown(KeyCode.O))
// {
// Debug.Log("解密" + ReturnBase64(ReturnBase64("123456789", true), false));
// }
// if (Input.GetKeyDown(KeyCode.Q))
// {
// Debug.Log("解密:" + ReturnBase64("MTE=", false));
// }
// }
}