Reputation: 157
While decompressing adhaar qr code sample data steps follow as given https://uidai.gov.in/images/resource/User_manulal_QR_Code_15032019.pdf, I got java.util.zip.DataFormatException: incorrect header check error while decompressing the byte array
// getting aadhaar sample qr code data from
// https://uidai.gov.in/images/resource/User_manulal_QR_Code_15032019.pdf
String s ="taking here Aadhaar sample qr code data";
BigInteger bi = new BigInteger(s, 10);
byte[] array = bi.toByteArray();
Inflater decompresser = new Inflater(true);
decompresser.setInput(array);
ByteArrayOutputStream outputStream = new
ByteArrayOutputStream(array.length);
byte[] buffer = new byte[1024];
while (!decompresser.finished()) {
int count = decompresser.inflate(buffer);
outputStream.write(buffer, 0, count);
}
outputStream.close();
byte[] output = outputStream.toByteArray();
String st = new String(output, 0, 255, "ISO-8859-1");
System.out.println("==========="+st);
Upvotes: 3
Views: 4550
Reputation: 256
This is the project which decoded the data Correctly: https://github.com/dimagi/AadharUID
It supports secure, xml and uid_number type
Upvotes: 2
Reputation: 154
The problem is that you are using Inflater class of java which uses Zlib compression algorithm. However in UIDAI secure QR code, GZip compression algorithm is being used. So the decompression logic has to be modified as following:-
ByteArrayOutputStream os = new ByteArrayOutputStream();
try {
ByteArrayInputStream in = new ByteArrayInputStream(data);
GZIPInputStream gis = new GZIPInputStream(in);
byte[] buffer = new byte[1024];
int len;
while((len = gis.read(buffer)) != -1){ os.write(buffer, 0, len);
}
os.close();
gis.close();
}
catch (IOException e) {
e.printStackTrace();
return null;
}
byte[] output = os.toByteArray();
Upvotes: 5