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); } }
public void bAuthed() { byte[] key = new byte[6]; byte blockNumber = 0x00; KEYTYPES keyType = KEYTYPES.ACR122_KEYTYPE_A; byte keyNumber = 0x20; try { if (!byte.TryParse("01", out blockNumber)) { // MessageBox.Show("Please key-in valid block number", "Invalid Input"); return; } if (!byte.TryParse("00", out keyNumber) || keyNumber > 31) { // MessageBox.Show("Please key-in key store number from 00 to 31", "Invalid Input"); return; } blockNumber = (byte)int.Parse("01"); acr1281UC1.authenticate(blockNumber, keyType, keyNumber); // MessageBox.Show("Authenticate Success!"); //GroupBoxChangeKey.Enabled = true; } catch (PcscException pcscException) { //MessageBox.Show(pcscException.Message, "PCSC Exception"); } catch (Exception ex) { } }