MCPcopy Create free account
hub / github.com/Maschell/JNUSTool / decryptContentHash

Method decryptContentHash

src/de/mas/jnustool/util/Decryption.java:328–379  ·  view source on GitHub ↗
(InputStream inputStream, OutputStream outputStream,Content content,byte[] h3)

Source from the content-addressed store, hash-verified

326 }
327
328 public boolean decryptContentHash(InputStream inputStream, OutputStream outputStream,Content content,byte[] h3) throws IOException{
329 int BLOCKSIZE = 0x10000;
330 int HASHBLOCKSIZE = 0xFC00;
331
332 long writeSize = HASHBLOCKSIZE;
333 long block = 0;
334
335 long soffset = 0;
336
337 long size = content.getSize()/0x10000*0xfc00;
338
339 if( soffset+size > writeSize )
340 writeSize = writeSize - soffset;
341
342
343 byte[] encryptedBlockBuffer = new byte[BLOCKSIZE];
344 ByteArrayBuffer overflow = new ByteArrayBuffer(BLOCKSIZE);
345
346 long wrote = 0;
347 int inBlockBuffer;
348
349 do{
350 inBlockBuffer = Util.getChunkFromStream(inputStream,encryptedBlockBuffer,overflow,BLOCKSIZE);
351 if(progressListener != null){
352 progressListener.addCurrent(inBlockBuffer);
353 }
354 if( writeSize > size )
355 writeSize = size;
356
357 byte[] output = decryptFileChunkHash(encryptedBlockBuffer, (int) block,content.getContentID(),h3);
358
359 if((wrote + writeSize) > size){
360 writeSize = (int) (size - wrote);
361 }
362
363 outputStream.write(output, (int)(0+soffset), (int)writeSize);
364 wrote +=writeSize;
365
366 block++;
367
368 if( soffset > 0)
369 {
370 writeSize = HASHBLOCKSIZE;
371 soffset = 0;
372 }
373 }while(wrote < size && (inBlockBuffer == BLOCKSIZE));
374
375 outputStream.close();
376 inputStream.close();
377 return true;
378
379 }
380
381
382 public byte[] decryptAsByte(FEntry fileEntry,String outputPath) throws IOException {

Callers

nothing calls this directly

Calls 5

getChunkFromStreamMethod · 0.95
decryptFileChunkHashMethod · 0.95
getSizeMethod · 0.80
addCurrentMethod · 0.80
getContentIDMethod · 0.45

Tested by

no test coverage detected