对字符串进行Base64编码解码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Common
{
public class Base64Code
{
Dictionary<string, int> _SmokeDict;
public Base64Code()
{
_SmokeDict = new Dictionary<string, int>();
int barOrderIndex = 0;
if (_SmokeDict.ContainsKey("A"))
{
barOrderIndex = _SmokeDict["A"] + 1;
_SmokeDict["A"] = _SmokeDict["A"] + 1;
}
else
{
//通过烟箱访问一次数据库,取出烟箱最大码值
int maxValue = 0;
barOrderIndex = maxValue + 1;
_SmokeDict.Add("A", barOrderIndex);
}
}
/// <summary>
/// 把二进制BYTE数组转换成base64字符串
/// </summary>
/// <param name="byteData"></param>
/// <returns></returns>
public static string ConvertByteToBase64(byte[] byteData)
{
return Convert.ToBase64String(byteData);
}
/// <summary>
///将base64字符串转换成二进制BTYE数组
/// </summary>
/// <param name="base64Str"></param>
/// <returns></returns>
public static byte[] ConvertBase64StrToByte(string base64Str)
{
return Convert.FromBase64String(base64Str);
}
/// <summary>
/// 把普通字符串转换成Base64字符串
/// </summary>
/// <param name="args"></param>
/// <returns></returns>
public static string ConvertStringToBase64(string args)
{
byte[] by = System.Text.Encoding.UTF8.GetBytes(args);
return Convert.ToBase64String(by);
}
/// <summary>
/// 把Base64字符串转换成普通字符串
/// </summary>
/// <param name="base64Str"></param>
/// <returns></returns>
public static string ConvertBase64ToString(string base64Str)
{
byte[] by = Convert.FromBase64String(base64Str);
return System.Text.Encoding.UTF8.GetString(by);
}
/// <summary>
/// utf-8解码
/// </summary>
/// <param name="code"></param>
/// <returns></returns>
public static string UrlDecode(string code)
{
return System.Web.HttpUtility.UrlDecode(code);
}
/// <summary>
/// utf-8编码
/// </summary>
/// <param name="code"></param>
/// <returns></returns>
public static string UrlEncode(string code)
{
return System.Web.HttpUtility.UrlEncode(code);
}
}
}