Base64编码/解码

复制代码
        /// <summary>
        /// Base64编码
        /// </summary>
        /// <param name="str">字符串</param>
        /// <returns></returns>
        public string StringToBase64(string str)
        {
            var bytes = System.Text.Encoding.UTF8.GetBytes(str);
            return Convert.ToBase64String(bytes);
        }

        /// <summary>
        /// Base64解码
        /// </summary>
        /// <param name="str">字符串</param>
        /// <returns></returns>
        public string Base64ToString(string str)
        {
            var outputb = Convert.FromBase64String(str);
            return System.Text.Encoding.UTF8.GetString(outputb);
        } 
复制代码

 

posted @   小小渔  阅读(140)  评论(0编辑  收藏  举报
努力加载评论中...
点击右上角即可分享
微信分享提示