@Override public void authenticate() throws IOException { final Mac mac = new HMac(new SHA256Digest()); mac.init(sha256MacParam); final byte[] buf = computeMac(mac); assert buf.length == mac.getMacSize(); if (!ArrayHelper.equals(buf, 0, footer, footer.length / 2, footer.length / 2)) throw new RaesAuthenticationException(); } }
/** * Authenticates all encrypted data in this read only file. * It is safe to call this method multiple times to detect if the file * has been tampered with meanwhile. * * @throws ZipAuthenticationException If the computed MAC does not match * the MAC declared in the WinZip AES entry. * @throws IOException On any I/O related issue. */ void authenticate() throws IOException { final Mac mac = new HMac(new SHA1Digest()); mac.init(sha1MacParam); final byte[] buf = computeMac(mac); if (!ArrayHelper.equals(buf, 0, authenticationCode, 0, authenticationCode.length)) throw new ZipAuthenticationException(entry.getName() + " (authenticated WinZip AES entry content has been tampered with)"); } }
break; assertTrue(read > 0); assertTrue(ArrayHelper.equals(getData(), off, buf, 0, read)); off += read;
break; assertTrue(read > 0); assertTrue(ArrayHelper.equals(getData(), off, buf, 0, read)); off += read;
@Test public final void testRandomReadChunks() throws IOException { final int length = (int) rrof.length(); for (int i = 100; --i >= 0; ) { int off = rnd.nextInt(length); assertRandomReadByte(rrof, off); assertRandomReadByte(trof, off); off++; final byte[] buf = new byte[rnd.nextInt(length / 100)]; int read = rrof.read(buf); if (read < 0) continue; if (buf.length > 0) { assertTrue(read > 0); assertTrue(ArrayHelper.equals(data, off, buf, 0, read)); java.util.Arrays.fill(buf, (byte) 0); trof.readFully(buf, 0, read); assertTrue(ArrayHelper.equals(data, off, buf, 0, read)); } else { assertTrue(read == 0); assertEquals(0, trof.read(buf)); } } } }
try { byte[] buf = new byte[getDataLength()]; assertTrue(ArrayHelper.equals(getData(), 0, buf, 0, in.read(buf))); } finally { in.close();
/** Las Vegas algorithm. */ @Test public final void testForwardReadChunks() throws IOException { final int length = (int) rrof.length(); int off = 0; int read; while (true) { final byte[] buf = new byte[rnd.nextInt(length / 100)]; read = rrof.read(buf); if (read < 0) break; if (buf.length > 0) { assertTrue(read > 0); assertTrue(ArrayHelper.equals(data, off, buf, 0, read)); java.util.Arrays.fill(buf, (byte) 0); trof.readFully(buf, 0, read); assertTrue(ArrayHelper.equals(data, off, buf, 0, read)); } else { assertTrue(read == 0); assertEquals(0, trof.read(buf)); } off += read; } assertEquals(off, length); assertEquals(-1, read); assertEquals(-1, trof.read(new byte[1])); assertEquals( 0, rrof.read(new byte[0])); assertEquals( 0, trof.read(new byte[0])); }
break; assertTrue(read > 0); assertTrue(ArrayHelper.equals(data, off, buf, 0, read)); off += read; } while (true);
} while (!ArrayHelper.equals( keyParam.getKey(), 2 * keyStrengthBytes, passwdVerifier, 0,
buf = new byte[klac.getMacSize()]; RaesOutputStream.klac(klac, length, buf); } while (!ArrayHelper.equals(this.footer, 0, buf, 0, buf.length / 2));
try { byte[] buf = new byte[getDataLength()]; assertTrue(ArrayHelper.equals(getData(), 0, buf, 0, in.read(buf))); } finally { in.close();