C#encode加密,JS decode解密
/// <summary> /// Base64加密,採用utf8編碼方式加密 /// </summary> /// <param name="source">待加密的明文</param> /// <returns>加密後的字串</returns> public static string Base64Encode(string source) { return Base64Encode(Encoding.UTF8, source); } /// <summary> /// Base64加密 /// </summary> /// <param name="encodeType">加密採用的編碼方式</param> /// <param name="source">待加密的明文</param> /// <returns></returns> public static string Base64Encode(Encoding encodeType, string source) { string encode = string.Empty; byte[] bytes = encodeType.GetBytes(source); try { encode = Convert.ToBase64String(bytes); } catch { encode = source; } return encode;
}
JS
var b = new Base64();
var str = b.encode("admin:admin");
alert("base64 encode:" + str);
//解密
str = b.decode(str);
alert("base64 decode:" + str);