java.lang.Objectandroid.device.MagManager
public class MagManager
The MagManager class is used to initialize and control the MSR card reader, and has the function of obtaining all data of the card.
To control the MSR card reader with this class, according to the following steps,
open
.
checkCard
.
getAllStripInfo
.
close
to close the slot for MSR card reader.
For more information about the MSR card reader, read MagManager sample.
Constructor Summary | |
---|---|
MagManager()
The MagManager class is used to initialize and control the MSR card reader. |
Method Summary | |
---|---|
int |
open()
Open the MSR reader. |
int |
close()
Close the MSR reader. |
int |
checkCard()
Check if a card swipe action has taken place. |
int |
getAllStripInfo(byte[] info)
Get information on all 3 tracks. |
int |
getSingleStripInfo(int strip,
byte[] info)
Get specific track information. |
int |
getEncryptStripInfo(int AlgMode,
int keyIndex,
byte[] info,
byte[] cardNo,
byte[] KSN)
Get information on all 3 Encrypt track data and plain text card NO. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
public MagManager()
public int open()
MagManager magManager = new MagManager();
int ret = magManager.open();
if (ret != 0) {
//open failed
}
public int close()
int ret = magManager.open();
if(ret == 0) {
magManager.close();
}
public int checkCard()
magManager.open();
int ret = magManager.checkCard();
if (ret != 0) {
//No card swiping detected
}
public int getAllStripInfo(byte[] info)
info
- To store the information.
The information is organized in TLV (tag length value) format.
The tag is 1 byte, with the following meaning:
magManager.open();
StringBuffer buffer = new StringBuffer();
byte[] stripInfo = new byte[1024];
int allLen = magManager.getAllStripInfo(stripInfo);
if (allLen > 0) {
//analytical data, information stored in stripInfo
int len = stripInfo[1];
if (len != 0)
//The first two digits of info should be 01, because it gets information of track 1.
buffer.append(" strip1: " + new String(stripInfo, 2, len));
int len2 = stripInfo[3 + len];
if (len2 != 0)
//The first two digits of info should be 02, because it gets information of track 2.
buffer.append(" \nstrip2: " + new String(stripInfo, 4 + len, len2));
int len3 = stripInfo[5 + len+len2];
if (len3 != 0 && len3 < 1024)
//The first two digits of info should be 03, because it gets information of track 3.
buffer.append(" \nstrip3: " + new String(stripInfo, 6 + len + len2, len3));
buffer.append("\n");
}
public int getSingleStripInfo(int strip, byte[] info)
strip
- Number of track. Values are as follows:
info
- To store the track information. The information is organized in TLV (tag length value) format. The tag is 1 byte, with the following meaning:
StringBuffer buffer = new StringBuffer();
byte[] info = new byte[1024];
public static final int TRACK_1 = 1; //For track 1
int len = magManager.getSingleStripInfo(TRACK_1, info);
if (len > 0) {
//analytical data, information stored in info
//The first two digits of info should be 01, because it gets information of track 1.
buffer.append(" strip1: " + new String(info, 2, len));
buffer.append("\n");
}
public int getEncryptStripInfo(int AlgMode, int keyIndex, byte[] info, byte[] cardNo, byte[] KSN)
AlgMode
- Data DES algorithm type. 1 is dupkt key.
keyIndex
- The DES Key index is 0 to 149.
info
- To store the encrypt information.
The information is organized in TLV (tag length value) format.
The tag is 1 byte, with the following meaning
cardNo
- Output. To store the plain text PAN.
KSN
- Output. To store the KSN key(10 bytes).
byte[] Info = new byte[1024];
byte[] cardNo = new byte[1024];
byte[] KSN = new byte[10];
int AlgMode = 1;
int keyIndex = 101;
int allLen = magManager.getEncryptStripInfo(AlgMode, keyIndex, Info, cardNo, KSN);
if (allLen > 0) {
//analytical data
}