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

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

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

Hashing.sha512介绍

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

代码示例

代码示例来源:origin: apache/incubator-druid

public static BloomKFilterHolder fromBloomKFilter(BloomKFilter filter) throws IOException
{
 byte[] bytes = BloomFilterSerializersModule.bloomKFilterToBytes(filter);
 return new BloomKFilterHolder(filter, Hashing.sha512().hashBytes(bytes));
}

代码示例来源:origin: apache/incubator-druid

public static BloomKFilterHolder fromBytes(byte[] bytes) throws IOException
{
 return new BloomKFilterHolder(
   BloomFilterSerializersModule.bloomKFilterFromBytes(bytes),
   Hashing.sha512().hashBytes(bytes)
 );
}

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

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

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

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

代码示例来源: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: runelite/runelite

if (bytes != null)
  ourHash = Hashing.sha512().hashBytes(bytes).toString();

代码示例来源:origin: com.capitalone.dashboard/core

static String hash(String apiKey) {
  if (!apiKey.startsWith(HASH_PREFIX)) {
    return HASH_PREFIX + Hashing.sha512().hashString(apiKey, StandardCharsets.UTF_8).toString();
  }
  return apiKey;
}

代码示例来源:origin: com.capitalone.dashboard/core

static String hash(String password) {
  if (!password.startsWith(HASH_PREFIX)) {
    return HASH_PREFIX + Hashing.sha512().hashString(password, StandardCharsets.UTF_8).toString();
  }
  return password;
}

代码示例来源:origin: org.eclipse.che.core/che-core-api-core

@Override
public String encrypt(String password) {
 requireNonNull(password, "Required non-null password");
 // generate salt
 final byte[] salt = new byte[SALT_BYTES_LENGTH];
 SECURE_RANDOM.nextBytes(salt);
 // sha512(password + salt)
 final HashCode hash =
   Hashing.sha512().hashBytes(Bytes.concat(password.getBytes(PWD_CHARSET), salt));
 final HashCode saltHash = HashCode.fromBytes(salt);
 // add salt to the hash, result length (512 / 8) * 2 + (64 / 8) * 2 = 144
 return hash.toString() + saltHash.toString();
}

代码示例来源:origin: org.eclipse.che.core/che-core-api-core

@Override
 public boolean test(String password, String passwordHash) {
  requireNonNull(password, "Required non-null password");
  requireNonNull(passwordHash, "Required non-null password's hash");
  // retrieve salt from the hash
  final int passwordHashLength = ENCRYPTED_PASSWORD_BYTES_LENGTH * 2;
  if (passwordHash.length() < passwordHashLength + SALT_BYTES_LENGTH * 2) {
   return false;
  }
  final HashCode saltHash = HashCode.fromString(passwordHash.substring(passwordHashLength));
  // sha1(password + salt)
  final HashCode hash =
    Hashing.sha512()
      .hashBytes(Bytes.concat(password.getBytes(PWD_CHARSET), saltHash.asBytes()));
  // test sha1(password + salt) + salt == passwordHash
  return (hash.toString() + saltHash.toString()).equals(passwordHash);
 }
}

代码示例来源:origin: org.apache.james/james-server-data-jpa

@SuppressWarnings("deprecation")
private static HashFunction chooseHashing(String algorithm) {
  switch (algorithm) {
    case "MD5":
      return Hashing.md5();
    case "SHA-256":
      return Hashing.sha256();
    case "SHA-512":
      return Hashing.sha512();
    default:
      return Hashing.sha1();
  }
}

代码示例来源:origin: RIPE-NCC/hadoop-pcap

@Override
  protected void processPacketPayload(Packet packet, byte[] payload) {
    if (payload.length > 0) {
      packet.put(HashPayloadPacket.PAYLOAD_SHA1_HASH, Hashing.sha1().hashBytes(payload).toString());
      packet.put(HashPayloadPacket.PAYLOAD_SHA256_HASH, Hashing.sha256().hashBytes(payload).toString());
      packet.put(HashPayloadPacket.PAYLOAD_SHA512_HASH, Hashing.sha512().hashBytes(payload).toString());
      packet.put(HashPayloadPacket.PAYLOAD_MD5_HASH, Hashing.md5().hashBytes(payload).toString());
    }
  }
}

代码示例来源:origin: nurkiewicz/download-server

public FileSystemPointer(File target) {
  try {
    this.target = target;
    this.tag = Files.hash(target, Hashing.sha512());
    final String contentType = java.nio.file.Files.probeContentType(target.toPath());
    this.mediaTypeOrNull = contentType != null ?
        MediaType.parse(contentType) :
        null;
  } catch (IOException e) {
    throw new IllegalArgumentException(e);
  }
}

代码示例来源:origin: com.github.unafraid.plugins/Plugins-API

public static HashCode getFileHash(File file) throws IOException {
  return Files.asByteSource(file).hash(Hashing.sha512());
}

代码示例来源:origin: FenixEdu/fenixedu-academic

private String generateConfirmationLink() {
  final String confirmationCode =
      Hashing.sha512()
          .hashString(
              getEmail() + System.currentTimeMillis() + hashCode()
                  + new Random(System.currentTimeMillis()).nextGaussian(), Charsets.UTF_8).toString();
  setConfirmationCode(confirmationCode);
  return FenixEduAcademicConfiguration.getConfiguration().getGenericApplicationEmailConfirmationLink() + confirmationCode
      + "&applicationExternalId=" + getExternalId();
}

代码示例来源:origin: com.google.guava/guava-tests

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

代码示例来源:origin: io.prestosql/presto-main

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

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

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

代码示例来源:origin: uk.co.nichesolutions.presto/presto-main

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

代码示例来源:origin: com.google.guava/guava-tests

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

相关文章