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.SoneImpl.java

/** {@inheritDoc} */
@Override/*  www. j a va 2  s  .  co  m*/
public synchronized String getFingerprint() {
    Hasher hash = Hashing.sha256().newHasher();
    hash.putString(profile.getFingerprint());

    hash.putString("Posts(");
    for (Post post : getPosts()) {
        hash.putString("Post(").putString(post.getId()).putString(")");
    }
    hash.putString(")");

    List<PostReply> replies = new ArrayList<PostReply>(getReplies());
    Collections.sort(replies, Reply.TIME_COMPARATOR);
    hash.putString("Replies(");
    for (PostReply reply : replies) {
        hash.putString("Reply(").putString(reply.getId()).putString(")");
    }
    hash.putString(")");

    List<String> likedPostIds = new ArrayList<String>(getLikedPostIds());
    Collections.sort(likedPostIds);
    hash.putString("LikedPosts(");
    for (String likedPostId : likedPostIds) {
        hash.putString("Post(").putString(likedPostId).putString(")");
    }
    hash.putString(")");

    List<String> likedReplyIds = new ArrayList<String>(getLikedReplyIds());
    Collections.sort(likedReplyIds);
    hash.putString("LikedReplies(");
    for (String likedReplyId : likedReplyIds) {
        hash.putString("Reply(").putString(likedReplyId).putString(")");
    }
    hash.putString(")");

    hash.putString("Albums(");
    for (Album album : rootAlbum.getAlbums()) {
        if (!Album.NOT_EMPTY.apply(album)) {
            continue;
        }
        hash.putString(album.getFingerprint());
    }
    hash.putString(")");

    return hash.hash().toString();
}

From source file:com.google.cloud.pubsub.proxy.gcloud.GcloudPubsub.java

private String getHashedName(String topic) {
    topic = Hashing.sha256().hashString(topic, StandardCharsets.UTF_8).toString();
    return topic;
}

From source file:View.JInternalFrameCadastroTreinador.java

/**
 * Aps a edio do objeto pega dados da aba Alterar e coloca no objeto.
 *
 * @param t Objeto a ser populado./*from  w w  w. j ava2s . co  m*/
 */
private void popularObjeto(Treinador t) {
    //TODO: Garantir que @param no  nulo
    /*O campo ID  gerado pelo banco de dados*/
    t.setNome(jTextFieldNomeTreinador.getText());
    t.setCpf((String) jFormattedTextFieldCpfTreinador.getText());
    t.setEndereco(jTextFieldEnderecoTreinador.getText());
    t.setLogin(jTextFieldLoginTreinador.getText());
    t.setSenha(Hashing.sha256().hashString(jPasswordFieldSenhaTreinador.getText(), Charsets.UTF_8).toString());
    t.setEmail(jTextFieldEmailTreinador.getText());
    t.setDataNascimento((Date) jFormattedTextFieldDataTreinador.getValue());
    /*Seta se o treinador sendo cadastrado  adiminstrador*/
    if (jCheckBoxAdministradorTreinador.isSelected()) {
        t.setAdministrador(1);
    } else {
        t.setAdministrador(0);
    }
}

From source file:com.google.cloud.storage.spi.DefaultStorageRpc.java

@Override
public String open(StorageObject object, Map<Option, ?> options) {
    try {/*  www. j av a 2s . com*/
        Insert req = storage.objects().insert(object.getBucket(), object);
        GenericUrl url = req.buildHttpRequest().getUrl();
        String scheme = url.getScheme();
        String host = url.getHost();
        String path = "/upload" + url.getRawPath();
        url = new GenericUrl(scheme + "://" + host + path);
        url.set("uploadType", "resumable");
        url.set("name", object.getName());
        for (Option option : options.keySet()) {
            Object content = option.get(options);
            if (content != null) {
                url.set(option.value(), content.toString());
            }
        }
        JsonFactory jsonFactory = storage.getJsonFactory();
        HttpRequestFactory requestFactory = storage.getRequestFactory();
        HttpRequest httpRequest = requestFactory.buildPostRequest(url,
                new JsonHttpContent(jsonFactory, object));
        HttpHeaders requestHeaders = httpRequest.getHeaders();
        requestHeaders.set("X-Upload-Content-Type",
                firstNonNull(object.getContentType(), "application/octet-stream"));
        String key = CUSTOMER_SUPPLIED_KEY.getString(options);
        if (key != null) {
            BaseEncoding base64 = BaseEncoding.base64();
            HashFunction hashFunction = Hashing.sha256();
            requestHeaders.set("x-goog-encryption-algorithm", "AES256");
            requestHeaders.set("x-goog-encryption-key", key);
            requestHeaders.set("x-goog-encryption-key-sha256",
                    base64.encode(hashFunction.hashBytes(base64.decode(key)).asBytes()));
        }
        HttpResponse response = httpRequest.execute();
        if (response.getStatusCode() != 200) {
            GoogleJsonError error = new GoogleJsonError();
            error.setCode(response.getStatusCode());
            error.setMessage(response.getStatusMessage());
            throw translate(error);
        }
        return response.getHeaders().getLocation();
    } catch (IOException ex) {
        throw translate(ex);
    }
}

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

@Override
public String open(StorageObject object, Map<Option, ?> options) {
    try {/*from  w  w  w  . ja v a 2s .c o m*/
        Insert req = storage.objects().insert(object.getBucket(), object);
        GenericUrl url = req.buildHttpRequest().getUrl();
        String scheme = url.getScheme();
        String host = url.getHost();
        String path = "/upload" + url.getRawPath();
        url = new GenericUrl(scheme + "://" + host + path);
        url.set("uploadType", "resumable");
        url.set("name", object.getName());
        for (Option option : options.keySet()) {
            Object content = option.get(options);
            if (content != null) {
                url.set(option.value(), content.toString());
            }
        }
        JsonFactory jsonFactory = storage.getJsonFactory();
        HttpRequestFactory requestFactory = storage.getRequestFactory();
        HttpRequest httpRequest = requestFactory.buildPostRequest(url,
                new JsonHttpContent(jsonFactory, object));
        HttpHeaders requestHeaders = httpRequest.getHeaders();
        requestHeaders.set("X-Upload-Content-Type",
                firstNonNull(object.getContentType(), "application/octet-stream"));
        String key = Option.CUSTOMER_SUPPLIED_KEY.getString(options);
        if (key != null) {
            BaseEncoding base64 = BaseEncoding.base64();
            HashFunction hashFunction = Hashing.sha256();
            requestHeaders.set("x-goog-encryption-algorithm", "AES256");
            requestHeaders.set("x-goog-encryption-key", key);
            requestHeaders.set("x-goog-encryption-key-sha256",
                    base64.encode(hashFunction.hashBytes(base64.decode(key)).asBytes()));
        }
        HttpResponse response = httpRequest.execute();
        if (response.getStatusCode() != 200) {
            GoogleJsonError error = new GoogleJsonError();
            error.setCode(response.getStatusCode());
            error.setMessage(response.getStatusMessage());
            throw translate(error);
        }
        return response.getHeaders().getLocation();
    } catch (IOException ex) {
        throw translate(ex);
    }
}

From source file:org.codice.ddf.security.filter.login.LoginFilter.java

/**
 * Adds SAML assertion to HTTP session./*from w  ww  . j  ava  2s.  co m*/
 *
 * @param httpRequest the http request object for this request
 * @param securityToken the SecurityToken object representing the SAML assertion
 */
private void addSamlToSession(HttpServletRequest httpRequest, SecurityToken securityToken) {
    if (securityToken == null) {
        LOGGER.debug("Cannot add null security token to session.");
        return;
    }

    HttpSession session = sessionFactory.getOrCreateSession(httpRequest);
    SecurityToken sessionToken = getSecurityToken(session);
    if (sessionToken == null) {
        addSecurityToken(session, securityToken);
    }
    SecurityAssertion securityAssertion = new SecurityAssertionImpl(securityToken);
    SecurityLogger.audit("Added SAML for user [{}] to session [{}]", securityAssertion.getPrincipal().getName(),
            Hashing.sha256().hashString(session.getId(), StandardCharsets.UTF_8).toString());
    int minutes = getExpirationTime();

    session.setMaxInactiveInterval(minutes * 60);
}

From source file:View.JInternalFrameCadastroAluno2.java

/**
 * Aps a edio do objeto pega dados da aba Alterar e coloca no objeto.
 *
 * @param a Objeto a ser populado.//from  w  ww  .j  ava2  s  .  co m
 */
private void popularObjeto(Aluno a) {
    //TODO: Garantir que @param no  nulo
    /*O campo ID  gerado pelo banco de dados*/
    a.setAltura(Float.parseFloat(jTextFieldAlturaAluno.getText()));
    a.setCpf((String) jFormattedTextFieldCpfAluno.getValue());
    a.setDataNascimento((Date) jFormattedTextFieldDataAluno.getValue());
    a.setEmail(jTextFieldEmailAluno.getText());
    a.setEndereco(jTextFieldEnderecoAluno.getText());
    //a.setId(Integer.parseInt(jTextFieldIdAluno.getText()));//E se for NULL?
    a.setLogin(jTextFieldLoginAluno.getText());
    a.setNome(jTextFieldNomeAluno.getText());
    a.setPeso(Float.parseFloat(jTextFieldPesoAluno.getText()));
    a.setSenha(Hashing.sha256().hashString(jPasswordFieldSenhaAluno.getText(), Charsets.UTF_8).toString());
    a.setUltimaEntrada((Date) jFormattedTextFieldUltimaEntradaAluno.getValue());
    a.setValidade((Date) jFormattedTextFieldValidadeAluno.getValue());

}

From source file:com.facebook.buck.io.filesystem.impl.DefaultProjectFilesystem.java

@Override
public String computeSha256(Path pathRelativeToProjectRoot) throws IOException {
    Path fileToHash = getPathForRelativePath(pathRelativeToProjectRoot);
    return Hashing.sha256().hashBytes(Files.readAllBytes(fileToHash)).toString();
}

From source file:com.facebook.buck.io.ProjectFilesystem.java

public String computeSha256(Path pathRelativeToProjectRoot) throws IOException {
    Path fileToHash = getPathForRelativePath(pathRelativeToProjectRoot);
    return Hashing.sha256().hashBytes(Files.readAllBytes(fileToHash)).toString();
}