本文整理汇总了Java中com.github.devnied.emvnfccard.utils.TlvUtil类的典型用法代码示例。如果您正苦于以下问题:Java TlvUtil类的具体用法?Java TlvUtil怎么用?Java TlvUtil使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TlvUtil类属于com.github.devnied.emvnfccard.utils包,在下文中一共展示了TlvUtil类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getLeftPinTry
import com.github.devnied.emvnfccard.utils.TlvUtil; //导入依赖的package包/类
/**
* Method used to get the number of pin try left
*
* @return the number of pin try left
* @throws CommunicationException
*/
protected int getLeftPinTry() throws CommunicationException {
int ret = UNKNOW;
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Get Left PIN try");
}
// Left PIN try command
byte[] data = provider.transceive(new CommandApdu(CommandEnum.GET_DATA, 0x9F, 0x17, 0).toBytes());
if (ResponseUtils.isSucceed(data)) {
// Extract PIN try counter
byte[] val = TlvUtil.getValue(data, EmvTags.PIN_TRY_COUNTER);
if (val != null) {
ret = BytesUtils.byteArrayToInt(val);
}
}
return ret;
}
示例2: parseFCIProprietaryTemplate
import com.github.devnied.emvnfccard.utils.TlvUtil; //导入依赖的package包/类
/**
* Method used to parse FCI Proprietary Template
*
* @param pData data to parse
* @return
* @throws CommunicationException
*/
protected byte[] parseFCIProprietaryTemplate(final byte[] pData) throws CommunicationException {
// Get SFI
byte[] data = TlvUtil.getValue(pData, EmvTags.SFI);
// Check SFI
if (data != null) {
int sfi = BytesUtils.byteArrayToInt(data);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("SFI found:" + sfi);
}
data = provider.transceive(new CommandApdu(CommandEnum.READ_RECORD, sfi, sfi << 3 | 4, 0).toBytes());
// If LE is not correct
if (ResponseUtils.isEquals(data, SwEnum.SW_6C)) {
data = provider.transceive(new CommandApdu(CommandEnum.READ_RECORD, sfi, sfi << 3 | 4, data[data.length - 1]).toBytes());
}
return data;
}
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("(FCI) Issuer Discretionary Data is already present");
}
return pData;
}
示例3: extractPublicData
import com.github.devnied.emvnfccard.utils.TlvUtil; //导入依赖的package包/类
/**
* Read public card data from parameter AID
*
* @param pAid card AID in bytes
* @param pApplicationLabel application scheme (Application label)
* @return true if succeed false otherwise
*/
protected boolean extractPublicData(final byte[] pAid, final String pApplicationLabel) throws CommunicationException {
boolean ret = false;
// Select AID
byte[] data = selectAID(pAid);
// check response
if (ResponseUtils.isSucceed(data)) {
// Parse select response
ret = parse(data, provider);
if (ret) {
// Get AID
String aid = BytesUtils.bytesToStringNoSpace(TlvUtil.getValue(data, EmvTags.DEDICATED_FILE_NAME));
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Application label:" + pApplicationLabel + " with Aid:" + aid);
}
card.setAid(aid);
card.setType(findCardScheme(aid, card.getCardNumber()));
card.setApplicationLabel(pApplicationLabel);
card.setLeftPinTry(getLeftPinTry());
}
}
return ret;
}
示例4: getLeftPinTry
import com.github.devnied.emvnfccard.utils.TlvUtil; //导入依赖的package包/类
/**
* Method used to get the number of pin try left
*
* @return the number of pin try left
* @throws CommunicationException
*/
protected int getLeftPinTry() throws CommunicationException {
int ret = UNKNOW;
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Get Left PIN try");
}
// Left PIN try command
byte[] data = provider.transceive(new CommandApdu(CommandEnum.GET_DATA, 0x9F, 0x17, 0).toBytes());
if (ResponseUtils.isSucceed(data)) {
// Extract PIN try counter
byte[] val = TlvUtil.getValue(data, EmvTags.PIN_TRY_COUNTER);
if (val != null) {
ret = BytesUtils.byteArrayToInt(val);
}
}
return ret;
}
示例5: parseFCIProprietaryTemplate
import com.github.devnied.emvnfccard.utils.TlvUtil; //导入依赖的package包/类
/**
* Method used to parse FCI Proprietary Template
*
* @param pData
* data to parse
* @return
* @throws CommunicationException
*/
protected byte[] parseFCIProprietaryTemplate(final byte[] pData) throws CommunicationException {
// Get SFI
byte[] data = TlvUtil.getValue(pData, EmvTags.SFI);
// Check SFI
if (data != null) {
int sfi = BytesUtils.byteArrayToInt(data);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("SFI found:" + sfi);
}
data = provider.transceive(new CommandApdu(CommandEnum.READ_RECORD, sfi, sfi << 3 | 4, 0).toBytes());
// If LE is not correct
if (ResponseUtils.isEquals(data, SwEnum.SW_6C)) {
data = provider.transceive(new CommandApdu(CommandEnum.READ_RECORD, sfi, sfi << 3 | 4, data[data.length - 1]).toBytes());
}
return data;
}
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("(FCI) Issuer Discretionary Data is already present");
}
return pData;
}
示例6: extractPublicData
import com.github.devnied.emvnfccard.utils.TlvUtil; //导入依赖的package包/类
/**
* Read public card data from parameter AID
*
* @param pAid
* card AID in bytes
* @param pApplicationLabel
* application scheme (Application label)
* @return true if succeed false otherwise
*/
protected boolean extractPublicData(final byte[] pAid, final String pApplicationLabel) throws CommunicationException {
boolean ret = false;
// Select AID
byte[] data = selectAID(pAid);
// check response
if (ResponseUtils.isSucceed(data)) {
// Parse select response
ret = parse(data, provider);
if (ret) {
// Get AID
String aid = BytesUtils.bytesToStringNoSpace(TlvUtil.getValue(data, EmvTags.DEDICATED_FILE_NAME));
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Application label:" + pApplicationLabel + " with Aid:" + aid);
}
card.setAid(aid);
card.setType(findCardScheme(aid, card.getCardNumber()));
card.setApplicationLabel(pApplicationLabel);
card.setLeftPinTry(getLeftPinTry());
}
}
return ret;
}
示例7: getGetProcessingOptions
import com.github.devnied.emvnfccard.utils.TlvUtil; //导入依赖的package包/类
/**
* Method used to create GPO command and execute it
*
* @param pPdol
* PDOL data
* @param pProvider
* provider
* @return return data
*/
protected byte[] getGetProcessingOptions(final byte[] pPdol, final IProvider pProvider) throws CommunicationException {
// List Tag and length from PDOL
List<TagAndLength> list = TlvUtil.parseTagAndLength(pPdol);
ByteArrayOutputStream out = new ByteArrayOutputStream();
try {
out.write(EmvTags.COMMAND_TEMPLATE.getTagBytes()); // COMMAND
// TEMPLATE
out.write(TlvUtil.getLength(list)); // ADD total length
if (list != null) {
for (TagAndLength tl : list) {
out.write(EmvTerminal.constructValue(tl));
}
}
} catch (IOException ioe) {
LOGGER.error("Construct GPO Command:" + ioe.getMessage(), ioe);
}
return pProvider.transceive(new CommandApdu(CommandEnum.GPO, out.toByteArray(), 0).toBytes());
}
示例8: testCurrency
import com.github.devnied.emvnfccard.utils.TlvUtil; //导入依赖的package包/类
@Test
public void testCurrency() {
SimpleDateFormat time = new SimpleDateFormat("HHmmss");
List<TagAndLength> list = TlvUtil.parseTagAndLength(BytesUtils
.fromString("9F 27 01 9F 02 06 5F 2A 02 9A 03 9F 36 02 9F 52 06 DF 3E 01 9F 21 03 9F 7C 14"));
EmvTransactionRecord record = new EmvTransactionRecord();
record.parse(
BytesUtils
.fromString("40 00 00 00 00 26 30 09 78 14 09 20 00 44 60 10 03 24 00 00 00 21 43 57 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 90 00"),
list);
Assertions.assertThat(record.getAmount()).isEqualTo(2630);
Assertions.assertThat(record.getCyptogramData()).isEqualTo("40");
Assertions.assertThat(record.getTransactionType()).isEqualTo(null);
Assertions.assertThat(record.getCurrency()).isEqualTo(CurrencyEnum.EUR);
Assertions.assertThat(record.getTerminalCountry()).isEqualTo(null);
Assertions.assertThat(record.getDate()).isNotNull();
Assertions.assertThat(time.format(record.getTime())).isEqualTo("214357");
}
示例9: transceive
import com.github.devnied.emvnfccard.utils.TlvUtil; //导入依赖的package包/类
@Override
public byte[] transceive(final byte[] pCommand) {
String response = null;
LOGGER.debug("send: " + BytesUtils.bytesToString(pCommand));
switch (step++) {
case 0:
response = "6F 57 84 0E 32 50 41 59 2E 53 59 53 2E 44 44 46 30 31 A5 45 BF 0C 42 61 10 4F 07 A0 00 00 00 42 10 10 50 02 43 42 87 01 01 9F 2A 08 03 00 00 00 00 00 00 00 61 18 4F 07 A0 00 00 00 03 10 10 50 0A 56 49 53 41 20 44 45 42 49 54 87 01 02 9F 2A 08 03 00 00 00 00 00 00 00 90 00";
break;
default:
response = "69 85";
}
LOGGER.debug("resp: " + response);
byte[] ret = BytesUtils.fromString(response);
try {
LOGGER.debug(TlvUtil.prettyPrintAPDUResponse(ret));
} catch (Exception e) {
}
return ret;
}
示例10: extractApplicationLabel
import com.github.devnied.emvnfccard.utils.TlvUtil; //导入依赖的package包/类
/**
* Method used to extract application label
*
* @return decoded application label or null
*/
protected String extractApplicationLabel(final byte[] pData) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Extract Application label");
}
String label = null;
byte[] labelByte = TlvUtil.getValue(pData, EmvTags.APPLICATION_LABEL);
if (labelByte != null) {
label = new String(labelByte);
}
return label;
}
示例11: getAids
import com.github.devnied.emvnfccard.utils.TlvUtil; //导入依赖的package包/类
/**
* Method used to get the aid list, if the Kernel Identifier is defined, <br/>
* this value need to be appended to the ADF Name in the data field of <br/>
* the SELECT command.
*
* @param pData FCI proprietary template data
* @return the Aid to select
*/
protected List<byte[]> getAids(final byte[] pData) {
List<byte[]> ret = new ArrayList<byte[]>();
List<TLV> listTlv = TlvUtil.getlistTLV(pData, EmvTags.AID_CARD, EmvTags.KERNEL_IDENTIFIER);
for (TLV tlv : listTlv) {
if (tlv.getTag() == EmvTags.KERNEL_IDENTIFIER && ret.size() != 0) {
ret.add(ArrayUtils.addAll(ret.get(ret.size() - 1), tlv.getValueBytes()));
} else {
ret.add(tlv.getValueBytes());
}
}
return ret;
}
示例12: parse
import com.github.devnied.emvnfccard.utils.TlvUtil; //导入依赖的package包/类
/**
* Method used to parse EMV card
*/
protected boolean parse(final byte[] pSelectResponse, final IProvider pProvider) throws CommunicationException {
boolean ret = false;
// Get TLV log entry
byte[] logEntry = getLogEntry(pSelectResponse);
// Get PDOL
byte[] pdol = TlvUtil.getValue(pSelectResponse, EmvTags.PDOL);
// Send GPO Command
byte[] gpo = getGetProcessingOptions(pdol, pProvider);
// Check empty PDOL
if (!ResponseUtils.isSucceed(gpo)) {
gpo = getGetProcessingOptions(null, pProvider);
// Check response
if (!ResponseUtils.isSucceed(gpo)) {
return false;
}
}
// Extract commons card data (number, expire date, ...)
if (extractCommonsCardData(gpo)) {
// Extract log entry
card.setListTransactions(extractLogEntry(logEntry));
ret = true;
}
return ret;
}
示例13: getLogFormat
import com.github.devnied.emvnfccard.utils.TlvUtil; //导入依赖的package包/类
/**
* Method used to get log format
*
* @return list of tag and length for the log format
* @throws CommunicationException
*/
protected List<TagAndLength> getLogFormat() throws CommunicationException {
List<TagAndLength> ret = new ArrayList<TagAndLength>();
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("GET log format");
}
// Get log format
byte[] data = provider.transceive(new CommandApdu(CommandEnum.GET_DATA, 0x9F, 0x4F, 0).toBytes());
if (ResponseUtils.isSucceed(data)) {
ret = TlvUtil.parseTagAndLength(TlvUtil.getValue(data, EmvTags.LOG_FORMAT));
}
return ret;
}
示例14: extractCardHolderName
import com.github.devnied.emvnfccard.utils.TlvUtil; //导入依赖的package包/类
/**
* Extract card holder lastname and firstname
*
* @param pData card data
*/
protected void extractCardHolderName(final byte[] pData) {
// Extract Card Holder name (if exist)
byte[] cardHolderByte = TlvUtil.getValue(pData, EmvTags.CARDHOLDER_NAME);
if (cardHolderByte != null) {
String[] name = StringUtils.split(new String(cardHolderByte).trim(), CARD_HOLDER_NAME_SEPARATOR);
if (name != null && name.length == 2) {
card.setHolderFirstname(StringUtils.trimToNull(name[0]));
card.setHolderLastname(StringUtils.trimToNull(name[1]));
}
}
}
示例15: getGetProcessingOptions
import com.github.devnied.emvnfccard.utils.TlvUtil; //导入依赖的package包/类
/**
* Method used to create GPO command and execute it
*
* @param pPdol PDOL data
* @param pProvider provider
* @return return data
*/
protected byte[] getGetProcessingOptions(final byte[] pPdol, final IProvider pProvider) throws CommunicationException {
// List Tag and length from PDOL 各一个,取两个
// pDol 9F 66 04 9F 02 06 9F 03 06 9F 1A 02 95 05 5F 2A 02 9A 03 9C 01 9F 37 04 90 00
// list = {[email protected]} size = 9
// 0 = {[email protected]} "Tag[9F 66] Name=Terminal Transaction Qualifiers, TagType=PRIMITIVE, ValueType=BINARY, Class=CONTEXT_SPECIFIC length: 4"
// 1 = {[email protected]} "Tag[9F 02] Name=Amount, Authorised (Numeric), TagType=PRIMITIVE, ValueType=NUMERIC, Class=CONTEXT_SPECIFIC length: 6"
// 2 = {[email protected]} "Tag[9F 03] Name=Amount, Other (Numeric), TagType=PRIMITIVE, ValueType=NUMERIC, Class=CONTEXT_SPECIFIC length: 6"
// 3 = {[email protected]} "Tag[9F 1A] Name=Terminal Country Code, TagType=PRIMITIVE, ValueType=TEXT, Class=CONTEXT_SPECIFIC length: 2"
// 4 = {[email protected]} "Tag[95] Name=Terminal Verification Results (TVR), TagType=PRIMITIVE, ValueType=BINARY, Class=CONTEXT_SPECIFIC length: 5"
// 5 = {[email protected]} "Tag[5F 2A] Name=Transaction Currency Code, TagType=PRIMITIVE, ValueType=TEXT, Class=APPLICATION length: 2"
// 6 = {[email protected]} "Tag[9A] Name=Transaction Date, TagType=PRIMITIVE, ValueType=NUMERIC, Class=CONTEXT_SPECIFIC length: 3"
// 7 = {[email protected]} "Tag[9C] Name=Transaction Type, TagType=PRIMITIVE, ValueType=NUMERIC, Class=CONTEXT_SPECIFIC length: 1"
// 8 = {[email protected]} "Tag[9F 37] Name=Unpredictable Number, TagType=PRIMITIVE, ValueType=BINARY, Class=CONTEXT_SPECIFIC length: 4"
List<TagAndLength> list = TlvUtil.parseTagAndLength(pPdol);
ByteArrayOutputStream out = new ByteArrayOutputStream();
try {
out.write(EmvTags.COMMAND_TEMPLATE.getTagBytes()); // COMMAND
// TEMPLATE
out.write(TlvUtil.getLength(list)); // ADD total length
if (list != null) {
for (TagAndLength tl : list) {
out.write(EmvTerminal.constructValue(tl));
}
}
} catch (IOException ioe) {
LOGGER.error("Construct GPO Command:" + ioe.getMessage(), ioe);
}
byte[] gpoCommand = new CommandApdu(CommandEnum.GPO, out.toByteArray(), 0).toBytes();
System.out.println(BytesUtils.bytesToString(gpoCommand));
return pProvider.transceive(gpoCommand);
}