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 void update(byte[] input, int offset, int len) 

Source Link

Document

Updates the digest using the specified array of bytes, starting at the specified offset.

Usage

From source file:eu.e43.impeller.Utils.java

public static byte[] sha1(String text) {
    try {//  w ww  . j a  v  a 2 s.c  om
        MessageDigest md = MessageDigest.getInstance("SHA-1");
        md.update(text.getBytes("utf-8"), 0, text.length());
        return md.digest();
    } catch (NoSuchAlgorithmException e) {
        throw new RuntimeException(e);
    } catch (UnsupportedEncodingException e) {
        throw new RuntimeException(e);
    }
}

From source file:net.cloudkit.enterprises.infrastructure.utilities.DigestsHelper.java

private static byte[] digest(InputStream input, String algorithm) throws IOException {
    try {/*from  www. j a va 2  s  .c  om*/
        MessageDigest messageDigest = MessageDigest.getInstance(algorithm);
        int bufferLength = 8 * 1024;
        byte[] buffer = new byte[bufferLength];
        int read = input.read(buffer, 0, bufferLength);

        while (read > -1) {
            messageDigest.update(buffer, 0, read);
            read = input.read(buffer, 0, bufferLength);
        }

        return messageDigest.digest();
    } catch (GeneralSecurityException e) {
        throw ExceptionHelper.unchecked(e);
    }
}

From source file:com.anybuy.util.DigestUtil.java

private static byte[] digest(InputStream input, String algorithm) throws IOException {
    try {//from   w w  w  . jav a2 s  .  co  m
        MessageDigest messageDigest = MessageDigest.getInstance(algorithm);
        int bufferLength = 8 * 1024;
        byte[] buffer = new byte[bufferLength];
        int read = input.read(buffer, 0, bufferLength);

        while (read > -1) {
            messageDigest.update(buffer, 0, read);
            read = input.read(buffer, 0, bufferLength);
        }

        return messageDigest.digest();
    } catch (GeneralSecurityException e) {
        throw ExceptionUtil.unchecked(e);
    }
}