C#中Base64之编码,解码方法

类别:.NET开发 点击:0 评论:0 推荐:
编码
public string EncodeBase64(string code_type,string code)
  {
   string encode = "";
   byte[] bytes = Encoding.GetEncoding(code_type).GetBytes(code);
   try
   {
    encode = Convert.ToBase64String(bytes);
   }
   catch
   {
    encode = code;
   }
   return encode;
  }
解码
public string DecodeBase64(string code_type,string code)
  {
   string decode = "";
   byte[] bytes = Convert.FromBase64String(code);
   try
   {
    decode = Encoding.GetEncoding(code_type).GetString(bytes);
   }
   catch
   {
    decode = code;
   }
   return decode;
  }

本文地址:http://com.8s8s.com/it/it42613.htm