Decode Drivers Licence Barcode

I get what you're saying. This is just a pet project for me. Not looking to make any financial gain here. In fact if anything, the people selling the scanners would make money because my software would still require a scanner to scan the barcode. So they gave me a scanner to test with. But it is useless without an SDK or some software.

Yeah same here, but I hope that something comes to light. When I am trying something I tend to succeed in it, even if it is just for personal gain like yourself. I have 3 different (and cheap) scanners that gets the raw data but that is as far as it goes.
 
are you using zxing to read the barcode? I am always getting nulll as a result
 
The problem is that most libraries do too much (padding etc) that just give errors. The math is simple, just use biginteger and do it directly. Mono.Security.Cryptography.RSAManaged also works.

You can even skip the pem parsing if you can get the e and n values in another way.

Code:
using System;
using System.IO;
using Org.BouncyCastle.Crypto.Parameters;
using Org.BouncyCastle.OpenSsl;
using Org.BouncyCastle.Math;

namespace Drivers
{
    class MainClass
    {
        private static byte[] GetPaddedValue (BigInteger value, int length)
        {
            byte[] result = value.ToByteArrayUnsigned();
            byte[] padded = new byte[length];
            Buffer.BlockCopy (result, 0, padded, (length - result.Length), result.Length);
            return padded;
        }

        private static byte[] EncryptValue (byte[] rgb, BigInteger e, BigInteger n, int size) 
        {
            BigInteger input = new BigInteger (rgb);
            BigInteger output = input.ModPow (e, n);
            byte[] result = GetPaddedValue (output, size);
            return result;
        }

        public static void Main (string[] args)
        {
            string longKey = @"-----BEGIN RSA PUBLIC KEY-----
MIGWAoGBAMqfGO9sPz+kxaRh/qVKsZQGul7NdG1gonSS3KPXTjtcHTFfexA4MkGA
mwKeu9XeTRFgMMxX99WmyaFvNzuxSlCFI/foCkx0TZCFZjpKFHLXryxWrkG1Bl9+
+gKTvTJ4rWk1RvnxYhm3n/Rxo2NoJM/822Oo7YBZ5rmk8NuJU4HLAhAYcJLaZFTO
sYU+aRX4RmoF
-----END RSA PUBLIC KEY-----";
            
            using (var reader = new StringReader(longKey))
            {
                var pem = new PemReader(reader);
                var o = (RsaKeyParameters)pem.ReadObject();

                var br = new BinaryReader (new FileStream ("myfile", FileMode.Open));

                br.ReadBytes (6);
                byte[] data = br.ReadBytes (128);

                var decrypted = EncryptValue (data, o.Exponent, o.Modulus, 128);
                string base64 = Convert.ToBase64String (decrypted);
                Console.WriteLine ("As base64: " + base64);
            } 


        }
    }
}
 
Thanks. Im trying to do it all within an app without having to rely on a device. Just a normal paper scanner
 
Thanks. Im trying to do it all within an app without having to rely on a device. Just a normal paper scanner

Zxing is designed for mobile devices where you have stream of images, so it doesn't work well for decoding a single scan, and apart from that it's bad at pdf417. You'll find many pdf417 libraries on google - just try a few.
 
The problem is that most libraries do too much (padding etc) that just give errors. The math is simple, just use biginteger and do it directly. Mono.Security.Cryptography.RSAManaged also works.

You can even skip the pem parsing if you can get the e and n values in another way.

Code:
using System;
using System.IO;
using Org.BouncyCastle.Crypto.Parameters;
using Org.BouncyCastle.OpenSsl;
using Org.BouncyCastle.Math;

namespace Drivers
{
    class MainClass
    {
        private static byte[] GetPaddedValue (BigInteger value, int length)
        {
            byte[] result = value.ToByteArrayUnsigned();
            byte[] padded = new byte[length];
            Buffer.BlockCopy (result, 0, padded, (length - result.Length), result.Length);
            return padded;
        }

        private static byte[] EncryptValue (byte[] rgb, BigInteger e, BigInteger n, int size) 
        {
            BigInteger input = new BigInteger (rgb);
            BigInteger output = input.ModPow (e, n);
            byte[] result = GetPaddedValue (output, size);
            return result;
        }

        public static void Main (string[] args)
        {
            string longKey = @"-----BEGIN RSA PUBLIC KEY-----
MIGWAoGBAMqfGO9sPz+kxaRh/qVKsZQGul7NdG1gonSS3KPXTjtcHTFfexA4MkGA
mwKeu9XeTRFgMMxX99WmyaFvNzuxSlCFI/foCkx0TZCFZjpKFHLXryxWrkG1Bl9+
+gKTvTJ4rWk1RvnxYhm3n/Rxo2NoJM/822Oo7YBZ5rmk8NuJU4HLAhAYcJLaZFTO
sYU+aRX4RmoF
-----END RSA PUBLIC KEY-----";
            
            using (var reader = new StringReader(longKey))
            {
                var pem = new PemReader(reader);
                var o = (RsaKeyParameters)pem.ReadObject();

                var br = new BinaryReader (new FileStream ("myfile", FileMode.Open));

                br.ReadBytes (6);
                byte[] data = br.ReadBytes (128);

                var decrypted = EncryptValue (data, o.Exponent, o.Modulus, 128);
                string base64 = Convert.ToBase64String (decrypted);
                Console.WriteLine ("As base64: " + base64);
            } 


        }
    }
}

I used this code, it did not fail however this doesn't decrypt it, almost looks more encrypted :) will still play around but here is the base64 for the first 128 bytes after your code. Will this be UTF7, UTF8 UTF32 or ASCII

Input: 019b0945000060e9a27a1e475f89af17cb3a5ae86bd91152d22fbca1f462ba8bd39e9341bb26ad82e3ab1b4e68069247b75286edb64fed476c1a444bba7ffeca8ac9ddcf629ac582a865b8eefec682f33de40e68a6fc08265df86ad058376db56e4a9d2a2da285d11f408493fb4706abc346632a156b517c87b58372a3afda8be11dbae4a8f5a3d1881559ce0c69acd026770fd9e75c28c4abd0b2796e70eca894d8546bd8456bdcd9af0aa112f78b56523471b46805ae844a66108ba2f12a28180e5ddded48436239eae212c6193d351201e6a24613d2482ddae552bf7e21729246667a9cd5c730ba4b80736586f5f90894b1017fcea7b299cd6241a266c4b7b28b704de1f0266025358d134686e1cac2ba9af74ea16b9524f4fca20792d2618beec8499dbab596f5a56531f26462c996dad5e1278400a5266c5b5aed2dd3cae135821148bdfd3d564ac127c90d3a125031cb263e63879dfdd10725dc80225a700e5d259a5a1d2340d7bd2d3fecc9b078e1726661e2c51b945b56d762fa3067f2b926dd2707a74e1535abf1a7ee09b0ec40689cd3b3b9995dfdda9b5f33482f1441afa48304a68b24b942464d0334d4b20c17a6f09d5db119257212f7b2d48860e22c64924dc53c03557624a020b175ef47553946ce2e60c3f2ba95865d73b2d440c2fd3eb3c9850447c249c869444dbc103d8197c5556355e6c46455b61aa0b176bcc73290b532726d4339bb35b144fecf5c5d4c5e90aef23fc9c9375ae7206f9ea5a22255365f7e0728e3360cb78562c805a4f9a2b4a674eb5af30b598b98b16227a223505e2e013e426296e8f3d1ff03d6506fa431162438afabbc4e8b9626e8821d6bd264ff9d35a2df90e2be27e0297c162a0a6bbc937f349d31413484b52ca27255b2263abde2793cb946387685de9662777cdf6808a18c3a25759ed4e6ab6410f7881b655421be87e3f3df100062f12ae806059ca3e11248557080a64e4ec6e0a46697cae4c5c5197e3defdc

Output

WBGeyAilMi+CTwZUipZQxUgJV1jC3vbnIaV36erGswFimTiae8+NCw9ge9M5OLvxBZAKJb3VFU1OrAtTMLgm/3/K7rzVm0oDf9Oy+FMzvaKVcaNNWlNg3JVd2CedHLfatq++o09nlYzkb6OzNP1ZK+jvROBz6nFgipf2x2t//2w=
 
Zxing is designed for mobile devices where you have stream of images, so it doesn't work well for decoding a single scan, and apart from that it's bad at pdf417. You'll find many pdf417 libraries on google - just try a few.

I use ScandIt, it scans the barcode quite good, but a dedicated 2d scanner works faster
 
I used this code, it did not fail however this doesn't decrypt it, almost looks more encrypted :) will still play around but here is the base64 for the first 128 bytes after your code. Will this be UTF7, UTF8 UTF32 or ASCII

It works for me. Make sure that you covert the hex to a byte array. Also skip the first 6 bytes, then decode a block of exactly 128 bytes.
 
It works for me. Make sure that you covert the hex to a byte array. Also skip the first 6 bytes, then decode a block of exactly 128 bytes.

Haha got it to work, forgot to convert the hex to bytes first before decoding it :).
It still have a lot of gibberish in between but Im sure with some manipulation I can get the text out.
 
It works for me. Make sure that you covert the hex to a byte array. Also skip the first 6 bytes, then decode a block of exactly 128 bytes.

Thanks for your help this far, its still a bit confusing but at least I can get the Surname, Initials, Nationality and ID Number from the first 128 bytes, the other bytes I cannot figure out yet
 
Hi Sweettoe, do you maybe have information about decoding the decrypted content, I've spent the day trying to figure out what Encoding the resulting bytes are but its completely confusing. With ASCII, UTF8 I get content like this

\u0001\u0002\u0003\u0004\u0005\u0002K\u0014\u0003\02\u0001\u0016?ZB???JANSEN?DC?ZA?ZA?0???415600002522?9206185036088\u0002 \u0011\u0005\u0010??\n\u0001\u0019?\u0006\u0018 \u0011\u0005\u0011 \u0016\u0005\u0010\u0001WI\u0004\0?\0?B?(@\00\u0004\u0010A?,??.Yo1\u001c0Nin?\u0004\u0011?y??\f\u0012\nB?

Just string manipulation wont work, im guessing that the start headers (\u00001 etc) mean something
 
Thanks for everyone's input here.

Croseven, how did you go from here:
I used this code, it did not fail however this doesn't decrypt it, almost looks more encrypted :) will still play around but here is the base64 for the first 128 bytes after your code. Will this be UTF7, UTF8 UTF32 or ASCII

Input: 019b0945000060e9a27a1e475f89af17cb3a5ae86bd91152d22fbca1f462ba8bd39e9341bb26ad82e3ab1b4e68069247b75286edb64fed476c1a444bba7ffeca8ac9ddcf629ac582a865b8eefec682f33de40e68a6fc08265df86ad058376db56e4a9d2a2da285d11f408493fb4706abc346632a156b517c87b58372a3afda8be11dbae4a8f5a3d1881559ce0c69acd026770fd9e75c28c4abd0b2796e70eca894d8546bd8456bdcd9af0aa112f78b56523471b46805ae844a66108ba2f12a28180e5ddded48436239eae212c6193d351201e6a24613d2482ddae552bf7e21729246667a9cd5c730ba4b80736586f5f90894b1017fcea7b299cd6241a266c4b7b28b704de1f0266025358d134686e1cac2ba9af74ea16b9524f4fca20792d2618beec8499dbab596f5a56531f26462c996dad5e1278400a5266c5b5aed2dd3cae135821148bdfd3d564ac127c90d3a125031cb263e63879dfdd10725dc80225a700e5d259a5a1d2340d7bd2d3fecc9b078e1726661e2c51b945b56d762fa3067f2b926dd2707a74e1535abf1a7ee09b0ec40689cd3b3b9995dfdda9b5f33482f1441afa48304a68b24b942464d0334d4b20c17a6f09d5db119257212f7b2d48860e22c64924dc53c03557624a020b175ef47553946ce2e60c3f2ba95865d73b2d440c2fd3eb3c9850447c249c869444dbc103d8197c5556355e6c46455b61aa0b176bcc73290b532726d4339bb35b144fecf5c5d4c5e90aef23fc9c9375ae7206f9ea5a22255365f7e0728e3360cb78562c805a4f9a2b4a674eb5af30b598b98b16227a223505e2e013e426296e8f3d1ff03d6506fa431162438afabbc4e8b9626e8821d6bd264ff9d35a2df90e2be27e0297c162a0a6bbc937f349d31413484b52ca27255b2263abde2793cb946387685de9662777cdf6808a18c3a25759ed4e6ab6410f7881b655421be87e3f3df100062f12ae806059ca3e11248557080a64e4ec6e0a46697cae4c5c5197e3defdc

Output

WBGeyAilMi+CTwZUipZQxUgJV1jC3vbnIaV36erGswFimTiae8+NCw9ge9M5OLvxBZAKJb3VFU1OrAtTMLgm/3/K7rzVm0oDf9Oy+FMzvaKVcaNNWlNg3JVd2CedHLfatq++o09nlYzkb6OzNP1ZK+jvROBz6nFgipf2x2t//2w=

to here:

Hi Sweettoe, do you maybe have information about decoding the decrypted content, I've spent the day trying to figure out what Encoding the resulting bytes are but its completely confusing. With ASCII, UTF8 I get content like this

\u0001\u0002\u0003\u0004\u0005\u0002K\u0014\u0003\02\u0001\u0016?ZB???JANSEN?DC?ZA?ZA?0???415600002522?9206185036088\u0002 \u0011\u0005\u0010??\n\u0001\u0019?\u0006\u0018 \u0011\u0005\u0011 \u0016\u0005\u0010\u0001WI\u0004\0?\0?B?(@\00\u0004\u0010A?,??.Yo1\u001c0Nin?\u0004\u0011?y??\f\u0012\nB?

Just string manipulation wont work, im guessing that the start headers (\u00001 etc) mean something

I get similar output to you in the first quote, not sure what I'm doing wrong
 
Thanks for everyone's input here.

Croseven, how did you go from here:


to here:



I get similar output to you in the first quote, not sure what I'm doing wrong


First I used the following code

private byte[] HexToByteArray(string hex)
{
return Enumerable.Range(0, hex.Length)
.Where(x => x % 2 == 0)
.Select(x => Convert.ToByte(hex.Substring(x, 2), 16))
.ToArray();
}

To take the hex to a byte array, the byte array should then be a length of 720 bytes.

Then I used the code sweettoe provided (skip 6 then take 128 bytes).

So in the end my code looks like the following

Code:
using System;
using System.IO;
using Org.BouncyCastle.Crypto.Parameters;
using Org.BouncyCastle.OpenSsl;
using Org.BouncyCastle.Math;

namespace Drivers
{
    class MainClass
    {
        private static byte[] GetPaddedValue (BigInteger value, int length)
        {
            byte[] result = value.ToByteArrayUnsigned();
            byte[] padded = new byte[length];
            Buffer.BlockCopy (result, 0, padded, (length - result.Length), result.Length);
            return padded;
        }

        private byte[] HexToByteArray(string hex)
        {
            return Enumerable.Range(0, hex.Length)
                             .Where(x => x % 2 == 0)
                             .Select(x => Convert.ToByte(hex.Substring(x, 2), 16))
                             .ToArray();
        }

        private static byte[] EncryptValue (byte[] rgb, BigInteger e, BigInteger n, int size) 
        {
            BigInteger input = new BigInteger (rgb);
            BigInteger output = input.ModPow (e, n);
            byte[] result = GetPaddedValue (output, size);
            return result;
        }

        public static void Main (string[] args)
        {
            string longKey = @"-----BEGIN RSA PUBLIC KEY-----
MIGWAoGBAMqfGO9sPz+kxaRh/qVKsZQGul7NdG1gonSS3KPXTjtcHTFfexA4MkGA
mwKeu9XeTRFgMMxX99WmyaFvNzuxSlCFI/foCkx0TZCFZjpKFHLXryxWrkG1Bl9+
+gKTvTJ4rWk1RvnxYhm3n/Rxo2NoJM/822Oo7YBZ5rmk8NuJU4HLAhAYcJLaZFTO
sYU+aRX4RmoF
-----END RSA PUBLIC KEY-----";

            string input = "019b0945000060e9a27a1e475f89af17cb3a5ae86bd91152d22fbca1f462ba8bd39e9341bb26ad82e3ab1b4e68069247b75286edb64fed476c1a444bba7ffeca8ac9ddcf629ac582a865b8eefec682f33de40e68a6fc08265df86ad058376db56e4a9d2a2da285d11f408493fb4706abc346632a156b517c87b58372a3afda8be11dbae4a8f5a3d1881559ce0c69acd026770fd9e75c28c4abd0b2796e70eca894d8546bd8456bdcd9af0aa112f78b56523471b46805ae844a66108ba2f12a28180e5ddded48436239eae212c6193d351201e6a24613d2482ddae552bf7e21729246667a9cd5c730ba4b80736586f5f90894b1017fcea7b299cd6241a266c4b7b28b704de1f0266025358d134686e1cac2ba9af74ea16b9524f4fca20792d2618beec8499dbab596f5a56531f26462c996dad5e1278400a5266c5b5aed2dd3cae135821148bdfd3d564ac127c90d3a125031cb263e63879dfdd10725dc80225a700e5d259a5a1d2340d7bd2d3fecc9b078e1726661e2c51b945b56d762fa3067f2b926dd2707a74e1535abf1a7ee09b0ec40689cd3b3b9995dfdda9b5f33482f1441afa48304a68b24b942464d0334d4b20c17a6f09d5db119257212f7b2d48860e22c64924dc53c03557624a020b175ef47553946ce2e60c3f2ba95865d73b2d440c2fd3eb3c9850447c249c869444dbc103d8197c5556355e6c46455b61aa0b176bcc73290b532726d4339bb35b144fecf5c5d4c5e90aef23fc9c9375ae7206f9ea5a22255365f7e0728e3360cb78562c805a4f9a2b4a674eb5af30b598b98b16227a223505e2e013e426296e8f3d1ff03d6506fa431162438afabbc4e8b9626e8821d6bd264ff9d35a2df90e2be27e0297c162a0a6bbc937f349d31413484b52ca27255b2263abde2793cb946387685de9662777cdf6808a18c3a25759ed4e6ab6410f7881b655421be87e3f3df100062f12ae806059ca3e11248557080a64e4ec6e0a46697cae4c5c5197e3defdc"
            
            using (var reader = new StringReader(longKey))
            {
                var pem = new PemReader(reader);
                var o = (RsaKeyParameters)pem.ReadObject();

                var br = new BinaryReader (HexToByteArray(input));

                br.ReadBytes (6);
                byte[] data = br.ReadBytes (128);

                var decrypted = EncryptValue (data, o.Exponent, o.Modulus, 128);
                string base64 = Convert.ToBase64String (decrypted);
                string ascii = Encoding.ASCII.GetString(decrypted);
                Console.WriteLine ("As base64: " + base64);
                Console.WriteLine ("As ASCII: " + ascii );
            } 


        }
    }
}


At this point I am stuck at decoding the decrypted content
 
Did anyone maybe succeed in decoding all information after the decryption is done, and also extract the image?
I can't seem to figure out what is still needed to do after it is decrypted, there is still a lot of unreadable text.
I tried to print as UTF8, UTF32, ASCII etc, some ISO encoding (can't remember) I also tried to do some bit shifting but still nothing worked. Only info that is clearly available is ID number, Title, Surname
 
are there decryption keys ? anyone ? share or sell ?
 
are there decryption keys ? anyone ? share or sell ?

You can find the keys here on this posts, just go back a few pages, there is also some C# code samples however they are incomplete.
I haven't worked on it again any further it is quite complicated after the keys are used.
 
Unless you know exactly how the binary/string data is stored you're going to have quite a tough time trying to figure it out. And forget about image decoding, thats impossible unless you have the original libraries. and even then its a flipping nightmare

honestly, if you're doing this for work, its far far far cheaper just to pay someone for the barcode decrypting and image decoding
 
Unless you know exactly how the binary/string data is stored you're going to have quite a tough time trying to figure it out. And forget about image decoding, thats impossible unless you have the original libraries. and even then its a flipping nightmare

honestly, if you're doing this for work, its far far far cheaper just to pay someone for the barcode decrypting and image decoding

Someone have to had it figured out already, its not worth it to pay someone unless they can share code, that I will do but to be depended on someone is costing more money than it should. Currently I am using a company (probably everyone use them) but their servers failed a number of times and you have to pay them for each device. We had (a month ago) 1 week downtime where the decryption stopped working on their servers.

So I disagree that its cheaper to pay someone to do it, unless they can share code that work, only then will I consider paying depending on the price.

one of the sites I have already moved to the code above where I extract the ID Number and the Initials, so I have made this now a priority to do the decryption instead of using someones tools
 
Top
Sign up to the MyBroadband newsletter
X