亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

解壓縮 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 關注
  • 153 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號