com.google.common.hash.Hashing.md5()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(7.5k)|赞(0)|评价(0)|浏览(233)

本文整理了Java中com.google.common.hash.Hashing.md5()方法的一些代码示例,展示了Hashing.md5()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Hashing.md5()方法的具体详情如下:
包路径:com.google.common.hash.Hashing
类名称:Hashing
方法名:md5

Hashing.md5介绍

[英]Returns a hash function implementing the MD5 hash algorithm (128 hash bits).
[中]返回实现MD5哈希算法的哈希函数(128个哈希位)。

代码示例

代码示例来源:origin: Graylog2/graylog2-server

private String collectorsToEtag(CollectorListResponse collectors) {
    return Hashing.md5()
        .hashInt(collectors.hashCode())  // avoid negative values
        .toString();
  }
}

代码示例来源:origin: Graylog2/graylog2-server

private String configurationToEtag(Configuration configuration) {
  return Hashing.md5()
      .hashInt(configuration.hashCode())  // avoid negative values
      .toString();
}

代码示例来源:origin: google/guava

public void testMd5() {
 HashTestUtils.checkAvalanche(Hashing.md5(), 100, 0.4);
 HashTestUtils.checkNo2BitCharacteristics(Hashing.md5());
 HashTestUtils.checkNoFunnels(Hashing.md5());
 HashTestUtils.assertInvariants(Hashing.md5());
 assertEquals("Hashing.md5()", Hashing.md5().toString());
}

代码示例来源:origin: google/guava

public void testHash() throws IOException {
 HashCode expectedHash = Hashing.md5().hashBytes(expected);
 assertEquals(expectedHash, source.hash(Hashing.md5()));
}

代码示例来源:origin: google/guava

public void testHashIntReverseBytesVsHashBytesIntsToByteArray() {
 int input = 42;
 assertEquals(
   Hashing.md5().hashBytes(Ints.toByteArray(input)),
   Hashing.md5().hashInt(Integer.reverseBytes(input)));
}

代码示例来源:origin: google/guava

public void testHashIntVsForLoop() {
 int input = 42;
 HashCode expected = Hashing.md5().hashInt(input);
 Hasher hasher = Hashing.md5().newHasher();
 for (int i = 0; i < 32; i += 8) {
  hasher.putByte((byte) (input >> i));
 }
 HashCode actual = hasher.hash();
 assertEquals(expected, actual);
}

代码示例来源:origin: google/guava

public void testHash() throws IOException {
 File asciiFile = getTestFile("ascii.txt");
 File i18nFile = getTestFile("i18n.txt");
 String init = "d41d8cd98f00b204e9800998ecf8427e";
 assertEquals(init, Hashing.md5().newHasher().hash().toString());
 String asciiHash = "e5df5a39f2b8cb71b24e1d8038f93131";
 assertEquals(asciiHash, Files.hash(asciiFile, Hashing.md5()).toString());
 String i18nHash = "7fa826962ce2079c8334cd4ebf33aea4";
 assertEquals(i18nHash, Files.hash(i18nFile, Hashing.md5()).toString());
}

代码示例来源:origin: google/guava

public void testHash_hashesCorrectly() throws Exception {
 byte[] buf = new byte[] {'y', 'a', 'm', 's'};
 HashCode expectedHash = Hashing.md5().hashBytes(buf);
 HashingOutputStream out = new HashingOutputStream(Hashing.md5(), buffer);
 out.write(buf);
 assertEquals(expectedHash, out.hash());
}

代码示例来源:origin: prestodb/presto

@Description("compute md5 hash")
@ScalarFunction
@SqlType(StandardTypes.VARBINARY)
public static Slice md5(@SqlType(StandardTypes.VARBINARY) Slice slice)
{
  return Slices.wrappedBuffer(Hashing.md5().hashBytes(slice.getBytes()).asBytes());
}

代码示例来源:origin: google/guava

public void testHash() throws IOException {
 ByteSource byteSource = new TestByteSource("hamburger\n".getBytes(Charsets.US_ASCII));
 // Pasted this expected string from `echo hamburger | md5sum`
 assertEquals("cfa0c5002275c90508338a5cdb2a9781", byteSource.hash(Hashing.md5()).toString());
}

代码示例来源:origin: google/guava

public void testHash_hashesCorrectly() throws Exception {
 HashCode expectedHash = Hashing.md5().hashBytes(testBytes);
 HashingInputStream in = new HashingInputStream(Hashing.md5(), buffer);
 byte[] buf = new byte[4];
 int numOfByteRead = in.read(buf, 0, buf.length);
 assertEquals(4, numOfByteRead);
 assertEquals(expectedHash, in.hash());
}

代码示例来源:origin: google/guava

public void testConcatenating_equals() {
 new EqualsTester()
   .addEqualityGroup(Hashing.concatenating(asList(Hashing.md5())))
   .addEqualityGroup(Hashing.concatenating(asList(Hashing.murmur3_32())))
   .addEqualityGroup(
     Hashing.concatenating(Hashing.md5(), Hashing.md5()),
     Hashing.concatenating(asList(Hashing.md5(), Hashing.md5())))
   .addEqualityGroup(
     Hashing.concatenating(Hashing.murmur3_32(), Hashing.md5()),
     Hashing.concatenating(asList(Hashing.murmur3_32(), Hashing.md5())))
   .addEqualityGroup(
     Hashing.concatenating(Hashing.md5(), Hashing.murmur3_32()),
     Hashing.concatenating(asList(Hashing.md5(), Hashing.murmur3_32())))
   .testEquals();
}

代码示例来源:origin: google/guava

public void testConcatenatingIterable_bits() {
 assertEquals(
   Hashing.md5().bits() + Hashing.md5().bits(),
   Hashing.concatenating(asList(Hashing.md5(), Hashing.md5())).bits());
 assertEquals(
   Hashing.md5().bits() + Hashing.murmur3_32().bits(),
   Hashing.concatenating(asList(Hashing.md5(), Hashing.murmur3_32())).bits());
 assertEquals(
   Hashing.md5().bits() + Hashing.murmur3_32().bits() + Hashing.murmur3_128().bits(),
   Hashing.concatenating(asList(Hashing.md5(), Hashing.murmur3_32(), Hashing.murmur3_128()))
     .bits());
}

代码示例来源:origin: google/guava

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));
}

代码示例来源:origin: google/guava

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());
}

代码示例来源:origin: google/guava

public void testHash_hashesCorrectlyForSkipping() throws Exception {
 HashCode expectedHash = Hashing.md5().hashBytes(new byte[] {'m', 's'});
 HashingInputStream in = new HashingInputStream(Hashing.md5(), buffer);
 long numOfByteSkipped = in.skip(2);
 assertEquals(2, numOfByteSkipped);
 byte[] buf = new byte[4];
 int numOfByteRead = in.read(buf, 0, buf.length);
 assertEquals(2, numOfByteRead);
 assertEquals(expectedHash, in.hash());
}

代码示例来源:origin: google/guava

public void testChecksForNull() throws Exception {
  NullPointerTester tester = new NullPointerTester();
  tester.testAllPublicInstanceMethods(
    new HashingOutputStream(Hashing.md5(), new ByteArrayOutputStream()));
  tester.testAllPublicStaticMethods(HashingOutputStream.class);
  tester.testAllPublicConstructors(HashingOutputStream.class);
 }
}

代码示例来源:origin: google/guava

public void testHash_hashesCorrectlyReadOutOfBound() throws Exception {
 HashCode expectedHash = Hashing.md5().hashBytes(testBytes);
 HashingInputStream in = new HashingInputStream(Hashing.md5(), buffer);
 byte[] buf = new byte[100];
 int numOfByteRead = in.read(buf, 0, buf.length);
 assertEquals(-1, in.read()); // additional read
 assertEquals(4, numOfByteRead);
 assertEquals(expectedHash, in.hash());
}

代码示例来源:origin: google/guava

public void testToString() {
 assertEquals("Hashing.md5()", Hashing.md5().toString());
 assertEquals("Hashing.sha1()", Hashing.sha1().toString());
 assertEquals("Hashing.sha256()", Hashing.sha256().toString());
 assertEquals("Hashing.sha512()", Hashing.sha512().toString());
}

代码示例来源:origin: google/guava

public void testChecksForNull() throws Exception {
  NullPointerTester tester = new NullPointerTester();

  tester.testAllPublicInstanceMethods(new HashingInputStream(Hashing.md5(), buffer));
  tester.testAllPublicStaticMethods(HashingInputStream.class);
  tester.testAllPublicConstructors(HashingInputStream.class);
 }
}

相关文章