https://github.com/sualeh/magnetictrackparser
Java library that can parse magnetic stripes from a bank issued credit card.
https://github.com/sualeh/magnetictrackparser
android credit-card java-library payment-processing payments
Last synced: 6 months ago
JSON representation
Java library that can parse magnetic stripes from a bank issued credit card.
- Host: GitHub
- URL: https://github.com/sualeh/magnetictrackparser
- Owner: sualeh
- License: other
- Created: 2014-04-29T03:32:49.000Z (over 11 years ago)
- Default Branch: main
- Last Pushed: 2025-03-01T22:59:17.000Z (7 months ago)
- Last Synced: 2025-03-29T10:05:33.873Z (6 months ago)
- Topics: android, credit-card, java-library, payment-processing, payments
- Language: Java
- Homepage:
- Size: 931 KB
- Stars: 79
- Watchers: 7
- Forks: 33
- Open Issues: 0
-
Metadata Files:
- Readme: .github/README.md
- Contributing: .github/CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE.md
- Code of conduct: .github/CODE_OF_CONDUCT.md
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
[](https://github.com/sualeh/magnetictrackparser/actions/workflows/quick_build.yml)
[](https://codeclimate.com/github/sualeh/magnetictrackparser)
[](https://codeclimate.com/github/sualeh/magnetictrackparser)
[](https://search.maven.org/search?q=g:us.fatehi%20magnetictrackparser*)> **:star: Star it :arrow_heading_up: if you love it!**
# 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](https://github.com/sualeh/creditcardnumber) 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.**## Resources
Some resources consulted are:
* [Magnetic stripe card](http://en.wikipedia.org/wiki/Magnetic_stripe_card) on Wikipedia for information about the format of track data.## Design Principles
- All classes are immutable and thread-safe
- Secure data follows standards in the
[Java Cryptography Architecture (JCA) Reference Guide](https://docs.oracle.com/javase/8/docs/technotes/guides/security/crypto/CryptoSpec.html#PBEEx)
- 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
- Android friendly## Download and Use in Projects
You can [download the jar on the Maven Central Repository](https://search.maven.org/artifact/us.fatehi/magnetictrackparser).
The [download page](https://search.maven.org/artifact/us.fatehi/magnetictrackparser)
has instructions on how to use the library in your Maven or Gradle build.## Examples
### How to Parse Magnetic Track Data
To parse a magnetic track, use code like:
```java
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
Name: Sualeh Fatehi
Expiration Date: 2016-04
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: 53502901
Card Brand: MasterCard
Last Four Digits: 5177
Passes Luhn Check? Yes
Is Primary Account Number Valid? Yes
Name: Sualeh Fatehi
Expiration Date: 2016-04
Is Expired? Yes
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](https://github.com/dimalinux/SwipeYours) uses _magnetictrackparser_. See details in [SetCardActivity.java](
https://github.com/dimalinux/SwipeYours/blob/master/src/main/java/to/noc/android/swipeyours/SetCardActivity.java#L34-L37). 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_.