Reading Bangladeshi NID and Smart Cards with ZXing

Bangladeshi NID and Smart Cards come printed with a 2D Datamatrix Barcode, known as PDF417. The information on the cards can be extracted without using an OCR solution through the barcode. We’ll be using Google’s ZXing library; learn about the basics of using it.

Mishandling of data or forgery of cards are treated as punishable offences around the world, including Bangladesh. Please consider legal consequences before proceeding. The reader is solely responsible for any legal consequences.

Dependencies

  • com.google.zxing:core
  • com.google.zxing:javase

Let’s add them to Gradle.

A Basic Scan

Pretty self-explanatory. You can build a BufferedImage from any InputStream, a file, a web request or socket connection and so on.

The rest is just parsing the resulting text and grabbing the results. I suggest reading through the source code of DecodeServlet.java for a better understanding.

Parsing NID

The format is pretty simple and straightforward. It looks kind of like XML. (I added line breaks for better visibility, there are no line-breaks in reality)

  • pin: NID Number
  • name: Name
  • DOB: Date of Birth (dd MMM yyyy)
  • FP: Fingerprint in FMR format (Binary)
  • rnd: No idea (Binary)
  • ds: No idea (Binary)

Parsing Smart Card

It is a bit different. No XML here! (There are no line-breaks, actually there are spaces where I put line-breaks)

  • NM: Name
  • HW: Smart Card Number
  • OL: Old NID Card Number
  • BR: Birthdate
  • PE: No idea
  • PR: No idea
  • VA: No idea
  • DT: Date of Issue (Probably)

Conclusion

Our NID and smart cards are great tools to automatically and manually validate identity for legitimate purposes. Please ensure great care and security for safeguarding the information of your customers. Do not overlook legal advice before implementing such a system on your premises.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.