Last active
May 30, 2023 18:57
-
-
Save hpkaushik121/84e426b262405d0e24e2d66e2ad18c10 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
public static byte[] readRecord(int recordNum, int sfi) { | |
//Valid Record numbers: 1 to 255 | |
//Valid SFI: 1 to 30 | |
//SFI=0 : Currently selected EF | |
if (recordNum < 1 || recordNum > 255) { | |
throw new IllegalArgumentException("Argument 'recordNum' must be in the rage 1 to 255. recordNum=" + recordNum); | |
} | |
if (sfi < 0 || sfi > 30) { | |
throw new IllegalArgumentException("Argument 'sfi' must be in the rage 1 to 30. Use 0 for currently selected EF. sfi=" + sfi); | |
} | |
byte P1 = (byte) recordNum; | |
//00010100 = P2 | |
//00010 = SFI (= 2 << 3) | |
// 100 = "Record number can be found in P1" (=4) | |
byte P2 = (byte) ((sfi << 3) | 4); | |
Log.debug("Iso7816Commands.readRecord() P1=" + P1 + " P2=" + P2); | |
byte[] cmd = new byte[5]; | |
//00 = No secure messaging | |
cmd[0] = 0x00; | |
//B2 = READ RECORD | |
cmd[1] = 0xb2; | |
//P1 = Record number or record identifier of the first record to be read ('00' indicates the current record) | |
cmd[2] = P1; | |
//P2 = SFI + 4 (Indicates that the record number can be found in P1) | |
cmd[3] = P2; | |
cmd[4] = 0x00; | |
return cmd; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment