Example #1
0
        public void LoadKey()
        {
            byte[]        key          = new byte[6];
            byte          keyNumber    = 0x20;
            KEY_STRUCTURE keyStructure = KEY_STRUCTURE.VOLATILE;

            try
            {
                if (!byte.TryParse("00", out keyNumber) || keyNumber > 01)
                {
                    // MessageBox.Show("Please key-in key store number from 00 to 01");
                    return;
                }


                //Key should be 6 bytes long
                key = getBytes("FFFFFF", ' ');
                if (key == null || key.Length != 6)
                {
                    //MessageBox.Show("Please key-in 6 bytes key");
                    return;
                }

                acr1281UC1.loadAuthKey(keyStructure, keyNumber, key);
            }
            catch (PcscException pcscException)
            {
                //MessageBox.Show(pcscException.Message, "PCSC Exception");
            }
            catch (Exception ex)
            {
            }
        }
Example #2
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);
            }
        }