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传需加密的值

posted on 2020-05-25 11:44  *tfe*  阅读(1022)  评论(0编辑  收藏  举报

导航