简体   繁体   中英

Not able to Decompress the byte array of new secure QR code of Aadhar

I am trying to decompress the byte array using GZipStream but getting error of "Found invalid data while decoding."

// getting aadhaar sample qr code data from // https://uidai.gov.in/images/resource/User_manulal_QR_Code_15032019.pdf

  static void Main(string[] args)
      {
          string source = "6979414848205548481619299442879901900893978332594614407044767717485407280104077714658698163325401659212830920734233047578454701810567032015270223682917915825234703754712504887921309181789607809168884583848396456653007022479356336240198130363930881632367124738541517499494458139647378808680614169273221404741476596583953169248831376224396335169577064812987140578144885819479190173537644970232125142253963784979138011318798385442436099901621998283624816070080504830712594525760596934341576755626791590403636878139861665599383319429228364434183913197958738697001410493839281298692342829951566712530309758759364649701153639921979798429707566199261950037418171329283207372048014948669160666776198414040633384677104717697507521717586776709084200364956178863636105988867260929887577092955570407803783021397897341999914616790441029837229129746669225095633201097644321593502503404440714110515167034889128258965583435965030225845348564582051521348800742574442877087774194668983516629631073341202705453382780613775427336949283388084891654484225446940941660942440637784744293259916479841407088189462964489670231866481904237338494872813098890875845640034370370387108798950180220865436012752487216677041817312930119747601017807577565413977545693375480131324240696099879479436722576566447939593195590684591261809038023122178172006150499569185218838749337238281597037288924464009997530938336798176023597292328320965086990184531426188862965408313308973495924965144113396593829090645266653313774582036138982013368561474719154447134894466611560589758251829063226370300282175823479569847261439348404558251402273730865053482214589180028302043821438357583302818374143973997002745047526405755760407045006694423501337081780299815080324840337828812644300041900356816429114261098230198976752026002079876882796597235615015594486182057781476152918170746403157005216896239428521706033466061587608065036133153074432195952131368564234168005447770190345777024917629879639171161719929852078265309160759260989590618158889891835294735614366674503961584445497685736312628248483551986529867423016255476553691922054241686230968975229511700928171281549902682365302333677412951788839806869796040512235899311734337858684531156721416280114473368826463098485252394260075790386415875290922570568686439586036262465414002334117870088922801660529414759784318799843806130096998190881240404138869293309782335305296720666220243304175086358278211355789957998014801209332293458940463859106591986434520433810583569309224929264228263841477378949329312443958215939294432669464260216534074560882723006838459792812340253078330291135526952675203790833430237852831740601433198364243363569730205351077393441691141240055900819091229931605146865520183001810239708464322588389956036291760175558843819105418234580239610174323636606095262722940143706063698846499673285377621180570537788160304936809915237889489342387891057012783726694920184573202789672963922380028271124448024265644396686341508447830351380242127542393849410283830409594988503246799544444687606954881510597515686410993828907588979699141180160893062603338104857903239845856783130275935413569275439908789983311663211937449259444259898972766208";
          BigInteger.TryParse(source, out BigInteger numBig);
          byte[] bytes = numBig.ToByteArray();
          string isoBytes2 = Decompress(bytes);
       }

static string Decompress(byte[] gzBuffer)
      {
          using (MemoryStream ms = new MemoryStream())
          {
              int msgLength = BitConverter.ToInt32(gzBuffer, 0);
              ms.Write(gzBuffer, 0, gzBuffer.Length);

              byte[] buffer = new byte[msgLength];

              ms.Position = 0;
              int length;
              using (GZipStream zip = new GZipStream(ms, CompressionMode.Decompress))
              {
                  length = zip.Read(buffer, 0, buffer.Length);
              }

              var data = new byte[length];
              Array.Copy(buffer, data, length);
              return Encoding.UTF8.GetString(data);

          }
      }

In C#, we need to do reverse byte array after coverting byte array from biginteger and before decompression the byte array. In Java, it not needed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM