/// <summary>
/// Base64编码及解码
/// </summary>
public class Base64
{
public static string Encode(string data)
{
try
{
byte[] dataByte = new byte[data.Length];
dataByte = System.Text.Encoding.UTF8.GetBytes(data);
string encodedData = Convert.ToBase64String(dataByte);
return encodedData;
}
catch (Exception e)
{
throw new Exception(e.Message);
}
}
/// <summary>
/// 解码(UTF8)
/// </summary>
/// <param name="data"></param>
/// <returns></returns>
public static string Decode(string data)
{
try
{
byte[] outputb = Convert.FromBase64String(data);
string result = System.Text.Encoding.UTF8.GetString(outputb);
return result;
}
catch (Exception e)
{
throw new Exception(se.Message);
}
}
}
string encodeStr = Base64.Encode("李明");
string decodeStr = Base64.Decode(encodeStr);
留言咨询