Created
August 4, 2018 12:07
-
-
Save sunnyy02/b0bd174ae6c6508188d5d219a5458188 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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