Skip to content

Instantly share code, notes, and snippets.

@sunnyy02
Created August 4, 2018 12:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sunnyy02/b0bd174ae6c6508188d5d219a5458188 to your computer and use it in GitHub Desktop.
Save sunnyy02/b0bd174ae6c6508188d5d219a5458188 to your computer and use it in GitHub Desktop.
function onAuthenticated(protocol, response)
{
sw = response.slice(-2);
if (sw[0] == 0x90 && sw[1] == 0x00)
{
// Read block 1 (16 bytes)
APDU_READ = [0xFF, 0xB0, 0x00, 0x01, 0x10];
readData(APDU_READ);
}
}
function readData(cmd, protocol) {
api.SCardTransmit(
_cardHandle,
protocol == API.SCARD_PROTOCOL_T0 ? API.SCARD_PCI_T0 : API.SCARD_PCI_T1,
cmd).then(function(result) {
result.get(function (ioRecvPci, response) {
// get the 2 last bytes
sw = response.slice(-2);
if (sw[0] == 0x90 && sw[1] == 0x00)
{
// convert to an ASCII string
result = "";
for (var i = 0; i < response.length; i++)
{
result += String.fromCharCode(response[i]);
}
}
}, onPcscLiteError);
}, onRequestFailed);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment