Base64 加密解密
/// <summary> /// 编码 Base64 /// </summary> /// <param name="code"></param> /// <param name="code_type">编码 </param> /// <returns></returns> public static string EncodeBase64(string code, string code_type = "utf-8") { string encode = ""; byte[] bytes = Encoding.GetEncoding(code_type).GetBytes(code); try { encode = Convert.ToBase64String(bytes); } catch { encode = code; } return encode; } /// <summary> /// 解码 Base64 /// </summary> /// <param name="code"></param> /// <param name="code_type">编码</param> /// <returns></returns> public static string DecodeBase64(string code, string code_type = "utf-8" ) { string decode = ""; byte[] bytes = Convert.FromBase64String(code); try { decode = Encoding.GetEncoding(code_type).GetString(bytes); } catch { decode = code; } return decode; }