Created
October 11, 2015 21:00
-
-
Save Franzaine/43f206b7a9c3e6bf2e63 to your computer and use it in GitHub Desktop.
Generate, decipher and print TOTP code
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
protected void communicateWithCard(IsoCard isoCard) { | |
try { | |
isoCard.connect(); | |
Apdu.transceiveAndRequireOk(Apdu.select(OTP_AID), isoCard); | |
setMainMessage("Select OK"); | |
long timeStamp = getTimeStamp(); | |
byte[] totpCodeApdu = Otp.totpCodeApdu(TOTP_CODE_NAME, timeStamp); | |
byte[] rawTotpCode = Apdu.transceiveAndGetResponse(totpCodeApdu, isoCard, Otp.SEND_REMAINING_APDU); | |
if(Apdu.hasStatus(rawTotpCode, Apdu.OK_APDU)){ | |
String totpCode = Otp.decipherTotpCode(rawTotpCode); | |
setMainMessage("TOTP code is: " + totpCode); | |
} | |
isoCard.close(); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment