Skip to content
Java library that can parse magnetic stripes from a bank issued credit card.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.

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.

Magnetic Track Parser depends on the Credit Card Number library.


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

Some resources consulted are:

Design Principles

  • 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
  • Internationalization of card numbers is supported
  • Validity is enforced by JUnit 5 tests
  • Java 8 or newer is required

Download and Use in Projects

You can download the jar on the Maven Central Repository. The download page has instructions on how to use the library in your Maven or Gradle build.


How to Parse Magnetic Track Data

To parse a magnetic track, use code like:

BankCardMagneticTrack 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 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.
You can’t perform that action at this time.