Base64编码
/// <summary>
/// 将字符串编码为Base64字符串
/// </summary>
/// <param name="str"></param>
/// <returns></returns>
public static string Base64Encode(string str)
{
byte[] barray;
barray = Encoding.Default.GetBytes(str);
return Convert.ToBase64String(barray);
}
/// <summary>
/// 将Base64字符串解码为普通字符串
/// </summary>
/// <param name="str"></param>
/// <returns></returns>
public static string Base64Decode(string str)
{
byte[] barray;
try
{
barray = Convert.FromBase64String(str);
return Encoding.Default.GetString(barray);
}
catch
{
return str;
}
}