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

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

Introduction

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

Prototype

public static HashFunction sha256() 

Source Link

Document

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

Usage

From source file:net.pterodactylus.sone.data.ImageImpl.java

@Override
public String getFingerprint() {
    Hasher hash = Hashing.sha256().newHasher();
    hash.putString("Image(");
    hash.putString("ID(").putString(id).putString(")");
    hash.putString("Title(").putString(title).putString(")");
    hash.putString("Description(").putString(description).putString(")");
    hash.putString(")");
    return hash.hash().toString();
}

From source file:org.apache.jackrabbit.oak.plugins.index.lucene.directory.IndexRootDirectory.java

static String getPathHash(String indexPath) {
    return Hashing.sha256().hashString(indexPath, Charsets.UTF_8).toString();
}

From source file:com.facebook.buck.util.config.Config.java

private HashCode computeOrderIndependentHashCode() {
    ImmutableMap<String, ImmutableMap<String, String>> rawValues = rawConfig.getValues();
    ImmutableSortedMap.Builder<String, ImmutableSortedMap<String, String>> expanded = ImmutableSortedMap
            .naturalOrder();//from   www.  jav  a 2 s.c o  m
    for (String section : rawValues.keySet()) {
        expanded.put(section, ImmutableSortedMap.copyOf(get(section)));
    }

    ImmutableSortedMap<String, ImmutableSortedMap<String, String>> sortedConfigMap = expanded.build();

    Hasher hasher = Hashing.sha256().newHasher();
    for (Entry<String, ImmutableSortedMap<String, String>> entry : sortedConfigMap.entrySet()) {
        hasher.putString(entry.getKey(), StandardCharsets.UTF_8);
        for (Entry<String, String> nestedEntry : entry.getValue().entrySet()) {
            hasher.putString(nestedEntry.getKey(), StandardCharsets.UTF_8);
            hasher.putString(nestedEntry.getValue(), StandardCharsets.UTF_8);
        }
    }

    return hasher.hash();
}

From source file:org.apache.servicecomb.serviceregistry.RegistryUtils.java

public static String calcSchemaSummary(String schemaContent) {
    return Hashing.sha256().newHasher().putString(schemaContent, Charsets.UTF_8).hash().toString();
}

From source file:org.jclouds.s3.filters.Aws4SignerBase.java

/**
 * hash input with sha256//from   w  ww.j  a  v a 2s . co m
 *
 * @param input
 * @return hash result
 * @throws HTTPException
 */
public static byte[] hash(InputStream input) throws HTTPException {
    HashingInputStream his = new HashingInputStream(Hashing.sha256(), input);
    try {
        ByteStreams.copy(his, ByteStreams.nullOutputStream());
        return his.hash().asBytes();
    } catch (IOException e) {
        throw new HttpException("Unable to compute hash while signing request: " + e.getMessage(), e);
    }
}

From source file:com.google.cloud.storage.spi.v1.HttpStorageRpc.java

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()));
    }//w  w w.  ja  v  a  2s . c  om
}

From source file:com.atypon.wayf.facade.impl.DeviceFacadeImpl.java

@Override
public String hashGlobalId(String globalId) {
    return globalId == null ? null : Hashing.sha256().hashString(globalId, StandardCharsets.UTF_8).toString();
}

From source file:com.cinchapi.common.io.Files.java

/**
 * Get a consistent temporary directory file path that represents the hash
 * for the specified {@code key}.//  w w  w  .j av  a  2 s.  co m
 * <p>
 * This method does <strong>NOT</strong> create a file at the returned path,
 * or any of the parent directories.
 * </p>
 * 
 * @param key the key to hash
 * @return the hashed file path
 */
public static Path getTemporaryHashedFilePath(String key) {
    String hash = Hashing.sha256().hashString(key, StandardCharsets.UTF_8).toString();
    ArrayBuilder<String> array = ArrayBuilder.builder();
    StringBuilder sb = new StringBuilder();
    char[] chars = hash.toCharArray();
    for (int i = 0; i < chars.length; ++i) {
        char c = chars[i];
        sb.append(c);
        if (i >= 4 && i % 4 == 0) {
            array.add(sb.toString());
            sb.setLength(0);
        }
    }
    return Paths.get(TMPDIR.toAbsolutePath().toString(), array.build());
}

From source file:com.ericsson.gerrit.plugins.projectgroupstructure.ProjectCreationValidator.java

private AccountGroup.UUID createGroup(String name) throws ValidationException {
    try {/*  www  .  j  a va2  s  . c  om*/
        GroupInfo groupInfo = null;
        try {
            groupInfo = createGroupFactory.create(name).apply(TopLevelResource.INSTANCE, new GroupInput());
        } catch (ResourceConflictException e) {
            // name already exists, make sure it is unique by adding a abbreviated
            // sha1
            String nameWithSha1 = name + "-"
                    + Hashing.sha256().hashString(name, Charsets.UTF_8).toString().substring(0, 7);
            log.info("Failed to create group name {} because of a conflict: {}, trying to create {} instead",
                    name, e.getMessage(), nameWithSha1);
            groupInfo = createGroupFactory.create(nameWithSha1).apply(TopLevelResource.INSTANCE,
                    new GroupInput());
        }
        return AccountGroup.UUID.parse(groupInfo.id);
    } catch (RestApiException | OrmException | IOException | ConfigInvalidException e) {
        log.error("Failed to create project {}: {}", name, e.getMessage(), e);
        throw new ValidationException(AN_ERROR_OCCURRED_MSG);
    }
}

From source file:org.jclouds.s3.filters.Aws4SignerBase.java

/**
 * hash input with sha256/*from w w  w .ja  va  2 s.  c  om*/
 *
 * @param bytes input bytes
 * @return hash result
 * @throws HTTPException
 */
public static byte[] hash(byte[] bytes) throws HTTPException {
    try {
        return ByteSource.wrap(bytes).hash(Hashing.sha256()).asBytes();
    } catch (IOException e) {
        throw new HttpException("Unable to compute hash while signing request: " + e.getMessage(), e);
    }
}