Java 6 library that can parse magnetic stripes from a bank issued credit card.
Java
Latest commit 1da8ff2 Jun 2, 2017 @sualeh sualeh Renaming all methods with "clear" to "dispose", to avoid terminology …
…mismatch with terms like "clear text".

README.md

Build Status Maven Central

Magnetic Track Parser

Magnetic Track Parser is a Java library that can parse magnetic track data from a bank issued credit card, such as might be returned from a USB magnetic card stripe reader.

The goal of this project is to use publicly and freely available documentation to create a reliable Java library to provide information about magnetic tracks and credit card numbers.

All classes are immutable and thread-safe. Secure data follows standards in the Java Cryptography Architecture (JCA) Reference Guide. The standard toString() function formats data in a readable form. Validity is enforced by JUnit tests.

Magnetic Track Parser depends on the Credit Card Number library.

Java 6 or newer is required. This library deliberately supports Java 6, to make it usable in Android apps.

Some resources consulted are:

Download

You can download the jar on the Maven Central Repository.

Maven Build

To use Magnetic Track Parser in your Maven build, include the following dependency. No repositories references are needed, since the jars are in the Maven Central Repository.

<dependency>
    <groupId>us.fatehi</groupId>
    <artifactId>magnetictrackparser</artifactId>
    <version>2.01.02</version>
</dependency>

Examples

How to Get Bank Card Information

To get bank card information, use code like:

AccountNumber pan = new AccountNumber("371449635398431");
BankCard card = new BankCard(pan);
System.out.println(card);

and you will get this output:

Bank Card Information: 
  Raw Account Number: 371449635398431
  Primary Account Number: 371449635398431
    Major Industry Identifier: 3 - Travel and entertainment and banking/financial
    Issuer Identification Number: 371449
    Card Brand: AmericanExpress
    Last Four Digits: 8431
    Passes Luhn Check? Yes
    Is Primary Account Number Valid? Yes

How to Parse Magnetic Track Data

To parse a magnetic track, use code like:

BankCardMagneticTrack track = 
  BankCardMagneticTrack.from("%B5350290149345177^FATEHI/SUALEH^16042010000000000000000000000000000567001000?;5350290149345177=16042010000056700100?");
System.out.println(track);

and you will get this output:

TRACK 1: %B5350290149345177^FATEHI/SUALEH^16042010000000000000000000000000000567001000?
  Primary Account Number: 5350290149345177
  Expiration Date: 2016-04
  Name: Sualeh Fatehi
  Service Code: 201
  Discretionary Data: 0000000000000000000000000000567001000
TRACK 2: ;5350290149345177=16042010000056700100?
  Primary Account Number: 5350290149345177
  Expiration Date: 2016-04
  Service Code: 201
  Discretionary Data: 0000056700100
TRACK 3:  Not Available.

Bank Card Information: 
  Raw Account Number: 5350290149345177
  Primary Account Number: 5350290149345177
    Major Industry Identifier: 5 - Banking and financial
    Issuer Identification Number: 535029
    Card Brand: MasterCard
    Last Four Digits: 5177
    Passes Luhn Check? Yes
    Is Primary Account Number Valid? Yes
  Expiration Date: 2016-04
    Is Expired: Yes
  Name: Sualeh Fatehi
  Service Code: 
    2 - Interchange: International interchange. Technology: Integrated circuit card.
    0 - Authorization Processing: Normal.
    1 - Allowed Services: No restrictions. PIN Requirements: None.

Who Uses

  • Dmitry Holodov's excellent Android app, SwipeYours uses magnetictrackparser. See details in SetCardActivity.java. This Android app helps developers understand the new Android Host Card Emulation feature for payments, and is written with open source, in the same spirit as magnetictrackparser.