Example usage for java.security MessageDigest update

List of usage examples for java.security MessageDigest update

Introduction

In this page you can find the example usage for java.security MessageDigest update.

Prototype

public final void update(ByteBuffer input) 

Source Link

Document

Update the digest using the specified ByteBuffer.

Usage

From source file:com.squarespace.gibson.GibsonUtils.java

private static void append(MessageDigest md, int value) {
    md.update((byte) (value >>> 24));
    md.update((byte) (value >>> 16));
    md.update((byte) (value >>> 8));
    md.update((byte) (value));
}

From source file:com.squarespace.gibson.GibsonUtils.java

private static void append(MessageDigest md, byte[] value) {
    md.update(value != null ? value : NULL);
}

From source file:Main.java

static String md5hash(String key) {
    MessageDigest hash = null;
    try {/*from w w  w.ja v  a  2 s. co  m*/
        hash = MessageDigest.getInstance(HASH_ALGORITHM_MD5);
    } catch (NoSuchAlgorithmException e) {
        return null;
    }

    hash.update(key.getBytes());
    byte[] digest = hash.digest();
    StringBuilder builder = new StringBuilder();
    for (int b : digest) {
        builder.append(Integer.toHexString((b >> 4) & 0xf));
        builder.append(Integer.toHexString((b >> 0) & 0xf));
    }
    return builder.toString();
}

From source file:com.streamsets.datacollector.updatechecker.UpdateChecker.java

static String getSha256(String id) {
    try {/*  ww  w .ja  va  2 s.co m*/
        MessageDigest md = MessageDigest.getInstance("SHA-256");
        md.update(id.getBytes("UTF-8"));
        return Base64.encodeBase64String(md.digest());
    } catch (Exception ex) {
        return "<UNKNOWN>";
    }
}

From source file:de.alpharogroup.crypto.sha.Hasher.java

/**
 * Hash./* w w  w  . ja v  a 2s  .  c o m*/
 *
 * @param hashIt
 *            the hash it
 * @param salt
 *            the salt
 * @param hashAlgorithm
 *            the hash algorithm
 * @param charset
 *            the charset
 * @return the string
 * @throws NoSuchAlgorithmException
 *             is thrown if instantiation of the MessageDigest object fails.
 */
public static String hash(final String hashIt, final String salt, final HashAlgorithm hashAlgorithm,
        final Charset charset) throws NoSuchAlgorithmException {
    final MessageDigest messageDigest = MessageDigest.getInstance(hashAlgorithm.getAlgorithm());
    messageDigest.reset();
    messageDigest.update(salt.getBytes(charset));
    return new String(messageDigest.digest(hashIt.getBytes(charset)), charset);
}

From source file:Main.java

/**
 * generates MD5 of input string//w ww. j  a v  a  2 s . co  m
 *
 * @param input string to be hashed
 * @return MD5 hash of string
 */
public static String getMD5(String input) {

    MessageDigest m = null;
    try {
        m = MessageDigest.getInstance("MD5");
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
    }
    m.reset();
    m.update(input.getBytes());
    byte[] digest = m.digest();
    BigInteger bigInt = new BigInteger(1, digest);
    String hashtext = bigInt.toString(16);
    //zero pad to get the full 32 chars.
    while (hashtext.length() < 32) {
        hashtext = "0" + hashtext;
    }
    return hashtext;
}

From source file:Main.java

public static String md5One(String s) {
    MessageDigest md = null;
    try {//  w w  w . j a  v a2  s.  co m
        md = MessageDigest.getInstance("MD5");
    } catch (NoSuchAlgorithmException e) {
        throw new RuntimeException(e.getMessage());
    }
    md.update(s.getBytes());
    return byteArrayToHexString(md.digest());
}

From source file:com.pieframework.runtime.utils.CertificateUtils.java

public static String getThumbPrint(X509Certificate certificate) {

    String thumbPrint = "";
    try {//from w ww  . j  av  a2  s .  com

        MessageDigest md = MessageDigest.getInstance("SHA-1");
        byte[] der = certificate.getEncoded();
        md.update(der);
        byte[] digest = md.digest();

        char[] hexDigits = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };

        StringBuffer buf = new StringBuffer(digest.length * 2);

        for (int i = 0; i < digest.length; ++i) {
            buf.append(hexDigits[(digest[i] & 0xf0) >> 4]);
            buf.append(hexDigits[digest[i] & 0x0f]);
        }

        thumbPrint = buf.toString();

    } catch (Exception e) {
        e.printStackTrace();
    }
    return thumbPrint;
}

From source file:com.aqnote.shared.cryptology.digest.MD.java

public final static String md2(byte[] src) {
    if (src == null)
        return "";
    try {//from   ww w. j  a va  2  s  .co m
        // MessageDigest messageDigest = MessageDigest.getInstance("MD2");
        MessageDigest messageDigest = MessageDigest.getInstance(OID_MD2, JCE_PROVIDER);
        messageDigest.update(src);
        return new String(ByteUtil.toHexBytes(messageDigest.digest()));
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
    } catch (NoSuchProviderException e) {
        e.printStackTrace();
    }
    return "";
}

From source file:com.aqnote.shared.cryptology.digest.MD.java

public final static String md4(byte[] src) {
    if (src == null)
        return "";
    try {/*from  www .  j  a va2  s.c o m*/
        // MessageDigest messageDigest = MessageDigest.getInstance("MD4");
        MessageDigest messageDigest = MessageDigest.getInstance(OID_MD4, JCE_PROVIDER);
        messageDigest.update(src);
        return new String(ByteUtil.toHexBytes(messageDigest.digest()));
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
    } catch (NoSuchProviderException e) {
        e.printStackTrace();
    }
    return "";
}