public static MD5 create() { return new MD5(); } }
BlockInputStream bl = new BlockInputStream(in, separator); MD5 md5 = new MD5(); String[] hashes = new String[3]; hashes[0] = MD5.create().update(data1).asString(); hashes[1] = MD5.create().update(data2).asString(); hashes[2] = MD5.create().update(data3).asString(); md5.update(data1, 0, data1.length); assertEquals(hashes[0], md5.toString()); md5.reset(); bl.next(); int r = 0; byte[] b = new byte[102400]; while ((r = bl.read(b)) != -1) { md5.update(b, 0, r); assertEquals(hashes[n], md5.toString()); n++;
@Test public void hash_test() throws IOException { String data = "foo bar\n"; Assert.assertTrue(MD5.create().check(data, "5ceaa7ed396ccb8e959c02753cb4bd18")); Assert.assertTrue(MD5.create().check(data.getBytes("utf-8"), hash)); MD5 md5 = MD5.create(); md5.update(data); md5.update(data); Assert.assertNotEquals("5ceaa7ed396ccb8e959c02753cb4bd18", md5.toString()); md5.reset(); md5.update(data); Assert.assertEquals("5ceaa7ed396ccb8e959c02753cb4bd18", md5.toString()); Assert.assertEquals("5ceaa7ed396ccb8e959c02753cb4bd18", MD5.create().update(in).asString()); md5 = MD5.create(); for (byte b : bytes) { md5.update(b); Assert.assertEquals("5ceaa7ed396ccb8e959c02753cb4bd18", md5.toString());
public void run() { int i = 1; while (i < k) { try { for (int j = 0; j < parts; j++) { int n = random.nextInt(data.length); out.write(data[n]); writed.addAndGet(data[n].length); md5Out.update(data[n], 0, data[n].length); } hashMapOut.put(i, md5Out.toString()); i++; md5Out.reset(); out.write(separator); writed.addAndGet(separator.length); } catch (IOException ex) { Logger.getLogger(BlockReaderTest.class.getName()).log(Level.SEVERE, null, ex); } } try { out.close(); } catch (IOException ex) { Logger.getLogger(BlockReaderTest.class.getName()).log(Level.SEVERE, null, ex); } } }).start();
final MD5 md5In = new MD5(); final MD5 md5Out = new MD5(); final PipedOutputStream out = new PipedOutputStream(); final PipedInputStream in = new PipedInputStream(out, 1024 * 1024); while (br.hasNext()) { md5In.reset(); while ((r = br.read(b)) != -1) { md5In.update(b, 0, r); t += r; hashMapIn.put(n, md5In.toString()); n++;
public void run() { int i = 1; while (i < 1000) { try { writer.setBlockLength(1024 * 1024); for (int j = 0; j < 1024; j++) { int n = random.nextInt(data.length); writer.write(data[n]); md5Out.update(data[n], 0, data[n].length); } hashMapOut.put(i, md5Out.toString()); i++; md5Out.reset(); } catch (IOException ex) { Logger.getLogger(BlockReaderTest.class.getName()).log(Level.SEVERE, null, ex); } } try { writer.close(); } catch (IOException ex) { Logger.getLogger(BlockReaderTest.class.getName()).log(Level.SEVERE, null, ex); } } }).start();
final MD5 md5In = new MD5(); final MD5 md5Out = new MD5(); final PipedOutputStream out = new PipedOutputStream(); final PipedInputStream in = new PipedInputStream(out, 1024 * 1024); br.next(); md5In.reset(); while ((r = br.read(b)) != -1) { md5In.update(b, 0, r); t += r; hashMapIn.put(n, md5In.toString()); n++;
public static MD5 create() { return new MD5(); } }
public String generateToken(Request request) { String auth = request.header(Header.KEY_AUTHORIZATION); if (auth == null) return request.paramWithDefault("token", ""); byte[] token = new byte[40]; // 16+16+8 MD5.create().update(getUser(request)).asBytes(token, 0); // key BytesHolder secret = hashes.get(new BytesHolder(token, 0, 16)); long timestamp = System.currentTimeMillis() + ttl; BytesTools.toBytes(timestamp, token, 32, 8); MD5.create().update(token, 32, 8).update(secret.bytes).asBytes(token, 16); return Base64.encodeToString(token, false, true); }
protected FileHolder createFileHolder(String path, boolean gzip) throws IOException { byte[] bytes = FileTools.bytes(path); ReadableByteBuffer gzipped = null; if (gzip) { ByteArrayOutputStream out = new ByteArrayOutputStream(bytes.length); GZIPOutputStream gout = new GZIPOutputStream(out); gout.write(bytes); gout.close(); byte[] byteArray = out.toByteArray(); ByteBuffer buffer = ByteBuffer.allocateDirect(byteArray.length); buffer.put(byteArray); buffer.flip(); gzipped = new ReadableByteBuffer(buffer); } ByteBuffer buffer = ByteBuffer.allocateDirect(bytes.length); buffer.put(bytes); buffer.flip(); String lastModified = HttpDateFormatterHolder.get().format(new Date(new File(path).lastModified())); String md5 = MD5.create().update(bytes).asString().toUpperCase(); return new FileHolder(new ReadableByteBuffer(buffer), md5, lastModified, gzipped); }
@Override public boolean filter(Request request, Response response) { String auth = request.header(Header.KEY_AUTHORIZATION); if (auth == null || !auth.startsWith("Digest ")) return returnNotAuthorized(response); DigestAuthData authData = new DigestAuthData(auth); String password = userPasswords.get(authData.username); if (password == null) return returnNotAuthorized(response); String ha1 = MD5.create().update(authData.username + ":" + realm + ":" + password).asString(); String ha2 = MD5.create().update(request.method().name() + ":" + request.path().toString()).asString(); String resp; if ("auth".equals(authData.qop)) resp = MD5.create().update(ha1 + ":" + authData.nonce + ":" + authData.nc + ":" + authData.cnonce + ":" + authData.qop + ":" + ha2).asString(); else resp = MD5.create().update(ha1 + ":" + authData.nonce + ":" + ha2).asString(); if (!resp.equals(authData.response)) return returnNotAuthorized(response); return true; }