增加packAPDU方法

        private void sendAPDU(string apdu)
        {
            apdu = packAPDU(apdu);
            int len = apdu.Length / 2;
            char[] chars = apdu.ToCharArray();
            string[] hexes = new string[len];
            byte[] bytes = new byte[len];
            for (int i = 0, j = 0; j < len; i = i + 2, j++)
            {
                hexes[j] = "" + chars[i] + chars[i + 1];
                bytes[j] = (byte)(Convert.ToInt16(hexes[j], 16));
            }
            sport.Write(bytes, 0, len);
        }
        private string packAPDU(string apdu)
        {
            int len = apdu.Length / 2;
            string lenStr = len.ToString("x");
            lenStr = lenStr.Length == 1 ? "0" + lenStr : lenStr;
            return "02" + "00" + lenStr + "80" + "FFFFFFFF" +
                apdu + "01" + "03";
        }

 

你可能感兴趣的:(J#)