Java SHA1 sha1hash(Collection nquads)

Here you can find the source of sha1hash(Collection nquads)

Description

A helper class to sha1 hash all the strings in a collection

License

Apache License

Parameter

Parameter Description
nquads a parameter

Declaration

private static String sha1hash(Collection<String> nquads) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

import java.util.Collection;

public class Main {
    /**//from  w  w w .  ja v  a2s .c  o m
     * A helper class to sha1 hash all the strings in a collection
     *
     * @param nquads
     * @return
     */
    private static String sha1hash(Collection<String> nquads) {
        try {
            // create SHA-1 digest
            final MessageDigest md = MessageDigest.getInstance("SHA-1");
            for (final String nquad : nquads) {
                md.update(nquad.getBytes("UTF-8"));
            }
            return encodeHex(md.digest());
        } catch (final NoSuchAlgorithmException e) {
            throw new RuntimeException(e);
        } catch (final UnsupportedEncodingException e) {
            throw new RuntimeException(e);
        }
    }

    private static String encodeHex(final byte[] data) {
        String rval = "";
        for (final byte b : data) {
            rval += String.format("%02x", b);
        }
        return rval;
    }
}

Related

  1. sha1Encode(byte[] content)
  2. SHA1Encode(String sourceString)
  3. sha1Hash()
  4. sha1hash(byte[] blob)
  5. sha1Hash(byte[] data)
  6. sha1hash(File f)
  7. sha1Hash(File file)
  8. sha1Hash(final String tohash)
  9. sha1Hash(InputStream in)