C# base64加密解密


    /// <summary>
    /// 实现Base64加密解密
    /// </summary>
    public sealed class Base64
    {
       
        /// <summary>
        /// BASE64编码加密
        /// </summary>
        /// <param name="s"></param>
        /// <param name="encode"></param>
        /// <returns></returns>
        public static string Base64Encode(string s, string encode)
        {
            return Convert.ToBase64String(Encoding.GetEncoding(encode).GetBytes(s));
        }

        /// <summary>
        /// BASE64编码解密
        /// </summary>
        /// <param name="s"></param>
        /// <param name="encode"></param>
        /// <returns></returns>
        public static string Base64Decode(string s, string encode)
        {
            return Encoding.GetEncoding(encode).GetString(Convert.FromBase64String(s));
        }

}

注:encode传utf-8,s传需加密的值

C# base64加密解密

上一篇:C#基础(一)——C#中反斜杠/n与/r的区别


下一篇:搭建consul 集群