Example usage for com.google.common.hash Hashing sha512

List of usage examples for com.google.common.hash Hashing sha512

Introduction

In this page you can find the example usage for com.google.common.hash Hashing sha512.

Prototype

public static HashFunction sha512() 

Source Link

Document

Returns a hash function implementing the SHA-512 algorithm (512 hash bits) by delegating to the SHA-512 MessageDigest .

Usage

From source file:utils.HashGenerator.java

/**
 * Return file's MD5.//from   ww w .j av  a 2 s .  co m
 * @param filePath the path where the file to have the md5 generated belongs.
 * @return The MD55 in String
 * @throws NoSuchAlgorithmException
 * @throws IOException
 */
public static String generateSHA512(String filePath) throws NoSuchAlgorithmException, IOException {
    File file = new File(filePath);
    String sha512 = BaseEncoding.base16().encode(Files.hash(file, Hashing.sha512()).asBytes()).toLowerCase();
    return sha512;
}

From source file:com.lithium.flow.util.HashFunctions.java

@Nonnull
public static HashFunction of(@Nonnull String name) {
    checkNotNull(name);/*from   w w w . j  a va  2 s  . com*/
    switch (name) {
    case "adler32":
        return Hashing.adler32();
    case "crc32":
        return Hashing.crc32();
    case "md5":
        return Hashing.md5();
    case "sha1":
        return Hashing.sha1();
    case "sha256":
        return Hashing.sha256();
    case "sha512":
        return Hashing.sha512();
    case "sipHash24":
        return Hashing.sipHash24();
    case "murmur3_32":
        return Hashing.murmur3_32();
    case "murmur3_128":
        return Hashing.murmur3_128();
    default:
        throw new RuntimeException("unknown hash: " + name);
    }
}

From source file:org.apache.druid.query.filter.BloomKFilterHolder.java

public static BloomKFilterHolder fromBloomKFilter(BloomKFilter filter) throws IOException {
    byte[] bytes = BloomFilterSerializersModule.bloomKFilterToBytes(filter);

    return new BloomKFilterHolder(filter, Hashing.sha512().hashBytes(bytes));
}

From source file:org.fenixedu.bennu.oauth.util.OAuthUtils.java

public static String generateCode() {
    return Hashing.sha512().hashString(UUID.randomUUID().toString(), StandardCharsets.UTF_8).toString();
}

From source file:org.apache.druid.query.filter.BloomKFilterHolder.java

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

From source file:org.vas.domain.repository.User.java

/**
 * Convenient method for password hashing
 *//*from   w w  w .j  av a  2  s  . c  o m*/
public static String hashPassword(String password) {
    return Hashing.sha512().hashString(password, Charsets.UTF_8).toString();
}

From source file:tech.beshu.ror.acl.blocks.rules.impl.__old_AuthKeySha512SyncRule.java

@Override
protected HashFunction getHashFunction() {
    return Hashing.sha512();
}

From source file:com.infinities.keystone4j.utils.PasswordUtils.java

public static boolean checkPassword(String password, String hashed) {
    logger.debug("password: {}, hashed: {}", new Object[] { password, hashed });
    if (Strings.isNullOrEmpty(password) || Strings.isNullOrEmpty(hashed)) {
        return false;
    }/*from w ww  .  ja va2  s  . co m*/

    String passwordUtf8 = null;
    try {
        passwordUtf8 = new String(verifyLengthAndtruncPassword(password).getBytes(UTF8), UTF8);
    } catch (UnsupportedEncodingException e) {
        logger.error(ENCODE_FAILED, e);
        return false;
    }
    String passwordSha512 = Hashing.sha512().hashString(passwordUtf8, Charsets.UTF_8).toString();
    logger.debug("password sha512: {}, hashed: {}", new Object[] { passwordSha512, hashed });
    return passwordSha512.equals(hashed);
}

From source file:org.vas.domain.repository.User.java

/**
 * Same as {@link User#hashPassword(String)} but with a char array
 * /*from  w ww.j  av a  2 s  .c  om*/
 * @param password
 * @return
 */
public static String hashPassword(char[] password) {
    return Hashing.sha512().hashString(new String(password), Charsets.UTF_8).toString();
}

From source file:org.fenixedu.academic.domain.candidacy.GenericApplicationRecomentation.java

public GenericApplicationRecomentation(GenericApplication application, String title, String name,
        String institution, String email) {
    setRootDomainObject(Bennu.getInstance());
    final String confirmationCode = Hashing.sha512().hashString(getEmail() + System.currentTimeMillis()
            + hashCode() + new Random(System.currentTimeMillis()).nextGaussian(), Charsets.UTF_8).toString();
    setConfirmationCode(confirmationCode);
    setEmail(email);// w w  w  .j a  va2  s .c  om
    setGenericApplication(application);
    setInstitution(institution);
    setTitle(title);
    setName(name);
    setRequestTime(new DateTime());
    sendEmailForRecommendation();
}