Refine search
@Override public Blob create(BlobInfo blobInfo, byte[] content, BlobTargetOption... options) { content = firstNonNull(content, EMPTY_BYTE_ARRAY); BlobInfo updatedInfo = blobInfo .toBuilder() .setMd5(BaseEncoding.base64().encode(Hashing.md5().hashBytes(content).asBytes())) .setCrc32c( BaseEncoding.base64() .encode(Ints.toByteArray(Hashing.crc32c().hashBytes(content).asInt()))) .build(); return internalCreate(updatedInfo, content, options); }
@Override public byte[] hash(byte[] input, int seed) { Hasher hasher = murmur3_128(seed).newHasher(); Funnels.byteArrayFunnel().funnel(input, hasher); return hasher.hash().asBytes(); } };
private String sha1(final File dir, final File sprite, final File css) throws IOException { try (Stream<Path> stream = Files.walk(dir.toPath())) { Hasher sha1 = Hashing.sha1().newHasher(); stream.filter(p -> !Files.isDirectory(p)) .forEach(p -> Try.run(() -> sha1.putBytes(Files.readAllBytes(p)))); if (sprite.exists()) { sha1.putBytes(Files.readAllBytes(sprite.toPath())); } if (css.exists()) { sha1.putBytes(Files.readAllBytes(css.toPath())); } return BaseEncoding.base16().encode(sha1.hash().asBytes()).toLowerCase(); } }
public void testConcatenatingVarArgs_bits() { assertEquals( Hashing.md5().bits() + Hashing.md5().bits(), Hashing.concatenating(Hashing.md5(), Hashing.md5()).bits()); assertEquals( Hashing.md5().bits() + Hashing.murmur3_32().bits(), Hashing.concatenating(Hashing.md5(), Hashing.murmur3_32()).bits()); assertEquals( Hashing.md5().bits() + Hashing.murmur3_32().bits() + Hashing.murmur3_128().bits(), Hashing.concatenating(Hashing.md5(), Hashing.murmur3_32(), Hashing.murmur3_128()).bits()); }
public void testConcatenatingHashFunction_makeHash() { byte[] md5Hash = Hashing.md5().hashLong(42L).asBytes(); byte[] murmur3Hash = Hashing.murmur3_32().hashLong(42L).asBytes(); byte[] combined = new byte[md5Hash.length + murmur3Hash.length]; ByteBuffer buffer = ByteBuffer.wrap(combined); buffer.put(md5Hash); buffer.put(murmur3Hash); HashCode expected = HashCode.fromBytes(combined); assertEquals( expected, Hashing.concatenating(Hashing.md5(), Hashing.murmur3_32()).hashLong(42L)); assertEquals( expected, Hashing.concatenating(asList(Hashing.md5(), Hashing.murmur3_32())).hashLong(42L)); }
public Void call() throws Exception { HttpWire wire = setUp(); InputStream in = wire.input(fromServer); ByteArrayOutputStream out = new ByteArrayOutputStream();// TODO copy(in, out); byte[] compare = md5().hashBytes(out.toByteArray()).asBytes(); Thread.sleep(100); assertEquals(base16().lowerCase().encode(compare), checkNotNull(sysHttpStreamMd5, sysHttpStreamMd5)); assertEquals(((BufferLogger) wire.getWireLog()).buff.toString().getBytes().length, 3331484); return null; } }
@Test(invocationCount = 100) public void testLessThan16Bytes() throws Exception { byte[] data = randomBytes(ThreadLocalRandom.current().nextInt(16)); HashCode expected = Hashing.murmur3_128().hashBytes(data); Slice actual = Murmur3Hash128.hash(Slices.wrappedBuffer(data)); assertEquals(actual.getBytes(), expected.asBytes()); }
private void checkLoginAsTheNewUser(String expectedUsername) { LoginResponse response = globalAdminClient.getSessionClient().loginUserInDomainWithHashOfPassword( expectedUsername, "", base16().lowerCase().encode(md5().hashString("password", UTF_8).asBytes())); assertNotNull(response); assertNotNull(response.getSessionKey()); assertNotNull(response.getJSessionId()); client.getSessionClient().logoutUser(response.getSessionKey()); } }
private static void setEncryptionHeaders( HttpHeaders headers, String headerPrefix, Map<Option, ?> options) { String key = Option.CUSTOMER_SUPPLIED_KEY.getString(options); if (key != null) { BaseEncoding base64 = BaseEncoding.base64(); HashFunction hashFunction = Hashing.sha256(); headers.set(headerPrefix + "algorithm", "AES256"); headers.set(headerPrefix + "key", key); headers.set( headerPrefix + "key-sha256", base64.encode(hashFunction.hashBytes(base64.decode(key)).asBytes())); } }
@Test public void testZoneKeyData() { Hasher hasher = Hashing.murmur3_128().newHasher(); SortedSet<TimeZoneKey> timeZoneKeysSortedByKey = ImmutableSortedSet.copyOf(new Comparator<TimeZoneKey>() { @Override public int compare(TimeZoneKey left, TimeZoneKey right) { return Short.compare(left.getKey(), right.getKey()); } }, TimeZoneKey.getTimeZoneKeys()); for (TimeZoneKey timeZoneKey : timeZoneKeysSortedByKey) { hasher.putShort(timeZoneKey.getKey()); hasher.putString(timeZoneKey.getId(), StandardCharsets.UTF_8); } // Zone file should not (normally) be changed, so let's make this more difficult assertEquals(hasher.hash().asLong(), -4582158485614614451L, "zone-index.properties file contents changed!"); }
@Test(invocationCount = 100) public void testLessThan4Bytes() throws Exception { byte[] data = randomBytes(ThreadLocalRandom.current().nextInt(4)); int expected = Hashing.murmur3_32().hashBytes(data).asInt(); int actual = Murmur3Hash32.hash(Slices.wrappedBuffer(data)); assertEquals(actual, expected); }
@Override public void run() { byte[] hash = Hashing.sha256().hashBytes(data).asBytes(); String hashStr = BaseEncoding.base16().encode(hash); archive.setHash(hash); String path = new StringBuilder() .append(hashStr.substring(0, 2)) .append('/') .append(hashStr.substring(2)) .toString(); try { try (InputStream in = minioClient.getObject(minioBucket, path)) { return; // already exists } catch (ErrorResponseException ex) { // doesn't exist } minioClient.putObject(minioBucket, path, new ByteArrayInputStream(data), data.length, "binary/octet-stream"); } catch (ErrorResponseException | InsufficientDataException | InternalException | InvalidArgumentException | InvalidBucketNameException | NoResponseException | IOException | InvalidKeyException | NoSuchAlgorithmException | XmlPullParserException ex) { logger.warn("unable to upload data to store", ex); } }
private String sha1(final CharSequence source) { return BaseEncoding.base16() .encode(Hashing .sha1() .hashString(source, charset) .asBytes()) .substring(0, 8).toLowerCase(); }
@Test public void testMD5PayloadEnclosing() throws IOException { Payload payload = Payloads.newPayload("foo"); HttpMessage payloadEnclosing = HttpMessage.builder().payload(payload).build(); assertEquals(fn.apply(payloadEnclosing), md5().hashString("foo", UTF_8).asBytes()); }
@Test(dependsOnMethods = "uploadMultipartBlob", singleThreaded = true) public void downloadParallelBlob() throws IOException { final File downloadedFile = new File(bigFile + ".downloaded"); blobStore.downloadBlob(CONTAINER, bigFile.getName(), downloadedFile, executor); String eTag = Files.hash(downloadedFile, Hashing.md5()).toString(); assertEquals(eTag, etag); }
public void testPutAfterHash() { Hasher sha1 = Hashing.sha1().newHasher(); assertEquals( "2fd4e1c67a2d28fced849ee1bb76e7391b93eb12", sha1.putString("The quick brown fox jumps over the lazy dog", Charsets.UTF_8) .hash() .toString()); try { sha1.putInt(42); fail(); } catch (IllegalStateException expected) { } }