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:Main.java

private static String getDigestValue(String s, String digestType) {
    String result = "";
    byte strTemp[] = s.getBytes();
    MessageDigest digestTemp;

    try {/*w  w w.j a v a 2s . com*/
        digestTemp = MessageDigest.getInstance(digestType);
        digestTemp.update(strTemp);

        byte[] digestValue = digestTemp.digest();

        result = bytesToHexString(digestValue);
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
        return null;
    }
    return result;
}

From source file:net.incrementalism.tooter.User.java

private static String hash(String password) {
    // NOTE: Insecure! Don't use this in a real application
    try {//from  ww  w  .j av  a 2 s.  co m
        MessageDigest md = MessageDigest.getInstance("SHA");
        md.update(password.getBytes("UTF-8"));
        return Base64.encodeBase64String(md.digest());
    } catch (NoSuchAlgorithmException e) {
        throw new AssertionError("No SHA");
    } catch (UnsupportedEncodingException e) {
        throw new AssertionError("No UTF-8");
    }
}

From source file:org.sentilo.common.rest.hmac.HMACBuilder.java

private static String calculateMD5(final String contentToEncode) throws NoSuchAlgorithmException {
    final MessageDigest digest = MessageDigest.getInstance(DIGEST_ALGORITHM);
    digest.update(contentToEncode.getBytes());
    return new String(Base64.encodeBase64(digest.digest()));
}

From source file:com.olayinka.file.transfer.Utils.java

public static String hash(String string) throws NoSuchAlgorithmException, UnsupportedEncodingException {
    MessageDigest md = null;
    md = MessageDigest.getInstance("SHA-256");
    md.update(string.getBytes());
    byte[] digest = md.digest();
    return String.valueOf(Hex.encodeHex(digest));
}

From source file:jp.co.opentone.bsol.framework.core.util.HashUtil.java

/**
 * ????????????.//www  . ja  v  a2  s . c o m
 * <h3>?</h3>
 * <pre>
 * 1. 3??
 * 2. ???(ab, 01, ...)?
 * 3. ALGORITHM?????
 *</pre>
 * @param   parameter ?
 * @return  ?
 */
public static String getString(String parameter) {
    String result = null;

    if (parameter != null) {
        String newParameter = parameter + parameter + parameter;
        byte[] encodedParameter = newParameter.getBytes();
        for (int i = 0; i < encodedParameter.length; i++) {
            encodedParameter[i] = (byte) (encodedParameter[i] + 1);
        }
        try {
            MessageDigest md = MessageDigest.getInstance(ALGORITHM);
            md.update(encodedParameter);
            result = new String(Hex.encodeHex(md.digest()));
        } catch (NoSuchAlgorithmException e) {
            // ALGORITHM?????????????
            throw new RuntimeException(e);
        }
    }
    return result;
}

From source file:Main.java

public static String getBytesDigestEncrypt(byte[] bytes, String algorithm) {
    if (algorithm.equals(MD5) || algorithm.equals(SHA1) || algorithm.equals(SHA256) || algorithm.equals(SHA384)
            || algorithm.equals(SHA512)) {
        MessageDigest digest = null;
        try {//from   w  ww .  j a va 2s.  c o m
            digest = MessageDigest.getInstance(algorithm);
            digest.update(bytes);
            return bytes2String(digest.digest());
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
    }
    return null;
}

From source file:org.jboss.aerogear.sync.jsonmergepatch.client.JsonMergePatchClientSynchronizer.java

public static String checksum(final JsonNode content) {
    try {/*from   w w w .  j av a 2 s .  c om*/
        final MessageDigest md = MessageDigest.getInstance("SHA1");
        md.update(content.asText().getBytes(UTF_8));
        return new BigInteger(1, md.digest()).toString(16);
    } catch (final Exception e) {
        throw new RuntimeException(e.getMessage(), e.getCause());
    }
}

From source file:de.marx_labs.utilities.common.util.HashUtil.java

public static String hash(String value) {
    MessageDigest digest;
    try {/* ww w.j  av  a2s  . c o  m*/
        digest = MessageDigest.getInstance("SHA-256");
        digest.update(value.getBytes("UTF-8"));
        byte[] hash = digest.digest();

        return new String(hash);
    } catch (Exception e) {
        logger.error("", e);
    }
    return null;
}

From source file:com.wso2telco.gsma.authenticators.Utility.java

/**
 * Returns the sha256 digest for a given string
 * @param input for the retrieving the sha256 hash
 */// www  . ja va  2 s . com
public static String generateSHA256Hash(String input) throws AuthenticationFailedException {
    String returnValue = null;
    try {
        MessageDigest md = MessageDigest.getInstance("SHA-256");
        md.update(input.getBytes());
        byte byteData[] = md.digest();
        //convert the byte to hex format
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < byteData.length; i++) {
            sb.append(Integer.toString((byteData[i] & 0xff) + 0x100, 16).substring(1));
        }
        returnValue = sb.toString();
    } catch (Exception e) {
        throw new AuthenticationFailedException("Failure while hashing the input value", e);
    }
    return returnValue;
}

From source file:Main.java

public static String getApkSignatureMD5String(Signature signature) {
    MessageDigest md;
    try {/*w  w  w  .j a  v a  2 s  . c  om*/
        md = MessageDigest.getInstance("MD5");

        md.update(signature.toByteArray());

        byte[] digest = md.digest();

        return toHexString(digest);
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
    }
    return "";
}