项目作者: AlexanderAnishchik

项目描述 :
Library for parsing magnetic stripe track data of credit cards
高级语言: C#
项目地址: git://github.com/AlexanderAnishchik/Credit-Card-Stripe-Parser.git
创建时间: 2018-08-31T22:12:56Z
项目社区:https://github.com/AlexanderAnishchik/Credit-Card-Stripe-Parser

开源协议:GNU General Public License v3.0

下载


Credit Card Magnetic Stripe Parser

Library for parsing magnetic stripe track data of credit cards

NuGet CreditCardStripeParser Package

A simple .Net Standard parser with following functionality:

  • Parse whole magnetic stripe from a card reader
  • Parse whole magnetic stripe with LRC codes after Track 1 or Track 2
  • Separately validate and parse Track 1, Track 2
  • Calculate and validate LRC to confirm the integrity of the data

Models

  1. /// <summary>
  2. /// ISO 7811-2 track one character encoding definition:
  3. /// SS FC PAN FS Name FS Date Discretionary Data ES LRC
  4. /// </summary>
  5. public class TrackOneModel
  6. {
  7. public char FormatCode { get; set; }
  8. public string PAN { get; set; }
  9. public string CardHolderName { get; set; }
  10. public string ExpirationDate { get; set; }
  11. public string ServiceCode { get; set; }
  12. public string DiscretionaryData { get; set; }
  13. public string SourceString { get; set; }
  14. }
  15. /// <summary>
  16. /// ISO 7811-2 Track Two encoding definition:
  17. /// SS PAN FS Date SVC CD Discretionary Data ES LRC
  18. /// </summary>
  19. public class TrackTwoModel
  20. {
  21. public string PAN { get; set; }
  22. public string ExpirationDate { get; set; }
  23. public string ServiceCode { get; set; }
  24. public string DiscretionaryData { get; set; }
  25. public string SourceString { get; set; }
  26. }
  27. public class FullTrackDataModel
  28. {
  29. public bool IsTrackOneValid { get; set; }
  30. public TrackOneModel TrackOne { get; set; }
  31. public bool IsTrackTwoValid { get; set; }
  32. public TrackTwoModel TrackTwo { get; set; }
  33. }
  34. }

Example Code:

  1. private String _testFullTrack = "%B5168755544412233^PKMMV/UNEMBOXXXX ^1807111100000000000000111000000?;5168755544412233=18071111000011100000?";
  2. var result = new FullTrackParser().ParseTrackOne(_testFullTrack);

will be parsed into a model:

  1. TrackOneModel testTrack1 = new TrackOneModel
  2. {
  3. FormatCode = 'B',
  4. PAN = "5168755544412233",
  5. CardHolderName = "PKMMV/UNEMBOXXXX ",
  6. ExpirationDate = "1807",
  7. ServiceCode = "111",
  8. DiscretionaryData = "100000000000000111000000",
  9. SourceString = "B5168755544412233^PKMMV/UNEMBOXXXX ^1807111100000000000000111000000"
  10. };