/// <summary>
/// GB2312编码
/// </summary>
/// <param name="str">待编码字符</param>
/// <returns>编码结果</returns>
public static string GB2312(string str)
{
StringBuilder sb = new StringBuilder();
//GB2321的编码方式
byte[] byStr = System.Text.Encoding.GetEncoding ("GB2312").GetBytes(str);
for (int i = ; i < byStr.Length; i++)
{
//转换为16进制方式 可选2,8,10,16进制
sb.Append(@"%" + Convert.ToString(byStr[i], ));
}
return (sb.ToString());
}
/// <summary>
/// GB2312解码
/// </summary>
/// <param name="str"></param>
/// <returns></returns>
public static string DeGB2312(string str)
{
byte[] bytes = new byte[str.Split('%').Length ];
int i=;
foreach (var item in str.Split('%'))
{
if (item !="")
{
//转换为16进制的字节
bytes[i] = Convert.ToByte(item,);
i++;
} }
//GB2312的解码
return Encoding.GetEncoding ("GB2312").GetString(bytes);
}
/// <summary>
/// UTF8编码
/// </summary>
/// <param name="str"></param>
/// <returns></returns>
public static string EnUTF8(string str)
{
StringBuilder sb = new StringBuilder();
byte[] byStr = System.Text.Encoding.UTF8.GetBytes(str);
for (int i = ; i < byStr.Length; i++)
{
sb.Append(@"%" + Convert.ToString(byStr[i], ));
} return (sb.ToString());
}
/// <summary>
/// UTF8解码
/// </summary>
/// <param name="str"></param>
/// <returns></returns>
public static string DeUTF8(string str)
{
byte[] bytes = new byte[str.Split('%').Length ];
int i=;
foreach (var item in str.Split('%'))
{
if (item !="")
{
bytes[i] = Convert.ToByte(item,);
i++;
} }
return Encoding.UTF8.GetString(bytes);
}
///C# 32位md5
/// <summary>
/// 获得32位的MD5加密
/// </summary>
/// <param name="str">加密字符串</param>
/// <returns>返回值</returns>
public static string GetMD532(string str)
{
MD5 md5 = MD5.Create();
byte[] d = md5.ComputeHash(Encoding.Default.GetBytes(str));
return BitConverter.ToString(d).Replace("-", "").ToLower(); }