为了账号安全,请及时绑定邮箱和手机立即绑定

解压缩 Java 中的字节数组

解压缩 Java 中的字节数组

森栏 2022-09-14 10:20:37
虽然解压缩adhaar qr代码示例数据步骤如下 https://uidai.gov.in/images/resource/User_manulal_QR_Code_15032019.pdf,但我得到了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.pdfString 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);
查看完整描述

2 回答

?
犯罪嫌疑人X

TA贡献2080条经验 获得超4个赞

问题是你使用的是使用Zlib压缩算法的java的膨胀类。然而,在UIDAI安全QR码中,正在使用GZip压缩算法。因此,解压缩逻辑必须修改如下:


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();


查看完整回答
反对 回复 2022-09-14
?
繁华开满天机

TA贡献1816条经验 获得超4个赞

这是正确解码数据的项目:https://github.com/dimagi/AadharUID

它支持安全、xml 和uid_number类型


查看完整回答
反对 回复 2022-09-14
  • 2 回答
  • 0 关注
  • 200 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号