将经过Base64编码的byte[]解码

来源:互联网 发布:招商银行外汇期权软件 编辑:程序博客网 时间:2024/05/01 03:43
 

经过编码的:string stt="7E 12 13 72 41 22 51 41 41 42 30 41 21 42 41 41 42 41 41 41 48 51 41 41 67 37 68 43 51 4F 68 75 78 5A 45 32 77 30 44 4A 50 48 35 50 6C 45 75 65 46 77 63 7A 39 58 64 33 50 77 53 55 68 78 4B 69 30 35 4C 76 31 49 41 3D 3D 7F"

        /// <summary>
        /// 字符串转十六进制
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        private byte[] StringToHex(string str)
        {
            string[] strs = str.Split(' ');
            byte[] bytes = new byte[strs.Length];
            int index = 0;
            foreach (string s in strs)
            {
                int hex = Convert.ToInt32(s, 16);
                bytes[index++] = (byte)hex;
            }
            return bytes;
        }

 

byte[] conding=StringToHex(str);

 //解码
            byte[] decondeByte = Convert.FromBase64CharArray(new ASCIIEncoding().GetChars(conding,0,conding.Length),0,conding.Length);

 

decondeByte就是经过Base64解码之后的Byte[]