Exemplo n.º 1
0
        public void loadAuthKey(KEY_STRUCTURE keyStructure, byte keyNumber, byte[] key)
        {
            if (key.Length != 6)
            {
                throw new Exception("Invalid key length");
            }


            apduCommand = new Apdu();
            apduCommand.setCommand(new byte[] { 0xFF,                   //Instruction Class
                                                0x82,                   //Instruction code
                                                (byte)keyStructure,     //Key Structure
                                                keyNumber,              //Key Number
                                                0x06 });                //Length of key

            //Set key to load
            apduCommand.data = key;

            sendCommand();

            if (!apduCommand.statusWordEqualTo(new byte[] { 0x90, 0x00 }))
            {
                throw new CardException("Load key failed", apduCommand.statusWord);
            }
        }
Exemplo n.º 2
0
        public void authenticate(byte blockNumber, KEYTYPES keyType, byte KeyNumber)
        {
            if (KeyNumber < 0x00 && KeyNumber > 0x20)
            {
                throw new Exception("Key number is invalid");
            }

            apduCommand = new Apdu();
            apduCommand.setCommand(new byte[] { 0xFF,           //Instruction Class
                                                0x86,           //Instruction Code
                                                0x00,           //RFU
                                                0x00,           //RFU
                                                0x05 });        //Length of authentication data bytes

            //Authentication Data Bytes
            apduCommand.data = new byte[] { 0x01,               //Version
                                            0x00,               //RFU
                                            (byte)blockNumber,  //Block Number
                                            (byte)keyType,      //Key Type
                                            KeyNumber };        //Key Number

            sendCommand();

            if (!apduCommand.statusWordEqualTo(new byte[] { 0x90, 0x00 }))
            {
                throw new CardException("Authenticate failed", apduCommand.statusWord);
            }
        }
Exemplo n.º 3
0
        public void valueBlock(byte blockNumber, VALUEBLOCKOPERATION transType, int amount)
        {
            Apdu apdu;

            apdu = new Apdu();
            apdu.setCommand(new byte[] { 0xFF, 0xD7, 0x00, blockNumber, 0x05 });

            apdu.data    = new byte[5];
            apdu.data[0] = (byte)transType;
            Array.Copy(Helper.intToByte(amount), 0, apdu.data, 1, 4);

            pcscConnection.sendCommand(ref apdu);

            if (!apdu.statusWordEqualTo(new byte[] { 0x90, 0x00 }))
            {
                throw new CardException("Value block operation failed", apdu.statusWord);
            }
        }
Exemplo n.º 4
0
        public byte[] getAnswerToSelect()
        {
            apduCommand = new Apdu();
            apduCommand.setCommand(new byte[] { 0xFF,
                                                0xCA,
                                                0x01,
                                                0x00,
                                                0x00 });

            apduCommand.lengthExpected = 50;

            sendCommand();

            if (!apduCommand.statusWordEqualTo(new byte[] { 0x90, 0x00 }))
            {
                throw new CardException("Unable to get Answer to Select (ATS)", apduCommand.statusWord);
            }

            return(apduCommand.response);
        }