public string Read(byte blockNumber, out string status) { status = ""; String read_str; //writeLabel.Content = ""; if (IsAuthenticated == true) { HiDWinscard.SCARD_IO_REQUEST sioreq; sioreq.dwProtocol = 0x2; sioreq.cbPciLength = 8; HiDWinscard.SCARD_IO_REQUEST rioreq; rioreq.cbPciLength = 8; rioreq.dwProtocol = 0x2; bcla = 0xFF; bins = 0xB0; bp1 = 0x0; bp2 = blockNumber; sendBuffer[0] = bcla; sendBuffer[1] = bins; sendBuffer[2] = bp1; sendBuffer[3] = bp2; sendBuffer[4] = 0x0; sendbufferlen = 0x5; receivebufferlen = 0x12; retval = HID.SCardTransmit(hCard, ref sioreq, sendBuffer, sendbufferlen, ref rioreq, receiveBuffer, ref receivebufferlen); if (retval == 0) { if ((receiveBuffer[receivebufferlen - 2] == 0x90) && (receiveBuffer[receivebufferlen - 1] == 0)) { //read_pressed = true; read_str = HexToBytenByteToHex.ToString(receiveBuffer); status = "> READ BINARY ( Block " + blockNumber.ToString() + " ) Successful\n"; return(read_str.Substring(0, ((int)(receivebufferlen - 2)) * 2)); } else { status = "> SCardTransmit" + " Failed(SW1 SW2 =" + BitConverter.ToString(receiveBuffer, (receivebufferlen - 2), 1) + " " + BitConverter.ToString(receiveBuffer, (receivebufferlen - 1), 1) + ")\n"; } } else { status = "> SCardTransmit" + " Failed... " + " Error Code: " + String.Format("{0:x}", retval) + "H\n"; } } return(""); }
public void LoadKey(int keynum, string key, out string status) { HiDWinscard.SCARD_IO_REQUEST sioreq; sioreq.dwProtocol = 0x2; sioreq.cbPciLength = 8; HiDWinscard.SCARD_IO_REQUEST rioreq; rioreq.cbPciLength = 8; rioreq.dwProtocol = 0x2; if (key.Length == 12) { Byte[] str3 = HexToBytenByteToHex.GetBytes(key, out discarded); //Encoding.ASCII.GetBytes(keych1); bcla = 0xFF; bins = 0x82; bp1 = 0x20; bp2 = (byte)keynum; len = 0x6; sendBuffer[0] = bcla; sendBuffer[1] = bins; sendBuffer[2] = bp1; sendBuffer[3] = bp2; sendBuffer[4] = len; for (int k = 0; k <= str3.Length - 1; k++) { sendBuffer[k + 5] = str3[k]; } sendbufferlen = 0xB; receivebufferlen = 255; retval = HID.SCardTransmit(hCard, ref sioreq, sendBuffer, sendbufferlen, ref rioreq, receiveBuffer, ref receivebufferlen); if (retval == 0) { if ((receiveBuffer[receivebufferlen - 2] == 0x90) && (receiveBuffer[receivebufferlen - 1] == 0)) { status = "> LOAD KEY ( No. " + keynum + " ) Successful \n"; } else { status = "> Load Key" + " Failed(SW1 SW2 =" + BitConverter.ToString(receiveBuffer, (receivebufferlen - 2), 1) + " " + BitConverter.ToString(receiveBuffer, (receivebufferlen - 1), 1) + ")\n"; } } else { status = "> Load Key" + " Failed... " + " Error Code: " + String.Format("{0:x}", retval) + "H\n"; } } else { status = "Klucz nie ma odpowiedniej długości!"; } }