Console.WriteLine(base64Encrypt("李狗蛋",true));
Console.WriteLine(base64Decode(base64Encrypt("李狗蛋", true)));
//base64加密
static string base64Encrypt(string str,bool IsEncrypt)
{
if (IsEncrypt)
{
return System.Convert.ToBase64String(System.Text.Encoding.Default.GetBytes(str));
}
else
{
return System.Text.Encoding.Default.GetString(System.Convert.FromBase64String(str));
}
}
//base64解密
static string base64Decode(string EncryptData)
{
try
{
return System.Text.Encoding.Default.GetString(System.Convert.FromBase64String(EncryptData));
}
catch (Exception ex)
{
return ex.Message;
}
}