对字符串进行编码解码

对字符串进行Base64编码解码

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Common
{
    public class Base64Code
    {
        Dictionary<string, int> _SmokeDict;

        public Base64Code()
        {
            _SmokeDict = new Dictionary<string, int>();

            int barOrderIndex = 0;
            if (_SmokeDict.ContainsKey("A"))
            {
                barOrderIndex = _SmokeDict["A"] + 1;
                _SmokeDict["A"] = _SmokeDict["A"] + 1;
            }
            else
            {
                //通过烟箱访问一次数据库,取出烟箱最大码值
                int maxValue = 0;
                barOrderIndex = maxValue + 1;
                _SmokeDict.Add("A", barOrderIndex);
            }

        }

        /// <summary>
        /// 把二进制BYTE数组转换成base64字符串
        /// </summary>
        /// <param name="byteData"></param>
        /// <returns></returns>
        public static string ConvertByteToBase64(byte[] byteData)
        {
            return Convert.ToBase64String(byteData);
        }
        /// <summary>
        ///将base64字符串转换成二进制BTYE数组
        /// </summary>
        /// <param name="base64Str"></param>
        /// <returns></returns>
        public static byte[] ConvertBase64StrToByte(string base64Str)
        {
            return Convert.FromBase64String(base64Str);
        }

        /// <summary>
        /// 把普通字符串转换成Base64字符串
        /// </summary>
        /// <param name="args"></param>
        /// <returns></returns>
        public static string ConvertStringToBase64(string args)
        {
            byte[] by = System.Text.Encoding.UTF8.GetBytes(args);
            return Convert.ToBase64String(by);
        }
        /// <summary>
        /// 把Base64字符串转换成普通字符串
        /// </summary>
        /// <param name="base64Str"></param>
        /// <returns></returns>
        public static string ConvertBase64ToString(string base64Str)
        {
            byte[] by = Convert.FromBase64String(base64Str);
            return System.Text.Encoding.UTF8.GetString(by);
        }
        /// <summary>
        /// utf-8解码
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        public static string UrlDecode(string code)
        {
            return System.Web.HttpUtility.UrlDecode(code);
        }
        /// <summary>
        /// utf-8编码
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        public static string UrlEncode(string code)
        {
            return System.Web.HttpUtility.UrlEncode(code);
        }
    }
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值