Example usage for java.security MessageDigest reset

List of usage examples for java.security MessageDigest reset

Introduction

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

Prototype

public void reset() 

Source Link

Document

Resets the digest for further use.

Usage

From source file:org.onebusaway.gtfs_realtime.nextbus.services.NextBusApiService.java

private File getCacheFileForUrl(String url) throws UnsupportedEncodingException {
    if (_cacheDirectory == null) {
        return null;
    }// w w w.j av a2s.co  m
    try {
        MessageDigest cript = MessageDigest.getInstance("SHA-1");
        cript.reset();
        cript.update(url.getBytes("utf8"));
        String name = new String(Hex.encodeHex(cript.digest()));
        return new File(_cacheDirectory, name);
    } catch (NoSuchAlgorithmException ex) {
        throw new IllegalStateException(ex);
    }
}

From source file:com.ccstats.crypto.AESWorker.java

/**
 * Hashes the plain password to provide a more secure experience.
 *
 * @param password the bytes of the plaintext password.
 *
 * @return The hashed password's characters in an array.
 *///from  w  w w . ja v  a 2  s. c om
private char[] hash(byte[] password) throws NoSuchAlgorithmException {
    MessageDigest md = MessageDigest.getInstance("MD5");
    md.reset();
    md.update(password);

    return Hex.encodeHex(md.digest());
}

From source file:org.pieShare.pieTools.pieUtilities.service.security.hashService.MD5Service.java

@Override
public byte[] hash(byte[] data) {
    MessageDigest messageDigest = provider.getMessageDigest();
    Validate.notNull(messageDigest);/*from   w  ww  . j  a v a2s. co  m*/
    messageDigest.update(data);
    byte[] resultByte = messageDigest.digest();
    messageDigest.reset();

    return resultByte;
}

From source file:br.vbathke.jenkins.UITestCaptureProjectAction.java

public String md5Hash(String data) throws NoSuchAlgorithmException {
    MessageDigest messageDigest;
    messageDigest = MessageDigest.getInstance("MD5");
    messageDigest.reset();
    messageDigest.update(data.getBytes(Charset.forName("UTF8")));
    byte[] resultByte = messageDigest.digest();
    String result = new String(Hex.encodeHex(resultByte));
    return result;
}

From source file:org.shredzone.commons.gravatar.impl.GravatarServiceImpl.java

@Override
public String computeHash(String mail) {
    try {/*from ww w .  ja  v  a 2 s . c  o  m*/
        MessageDigest md5 = MessageDigest.getInstance("MD5");
        md5.reset();
        md5.update(mail.trim().toLowerCase().getBytes("UTF-8"));

        byte[] digest = md5.digest();

        return IntStream.range(0, digest.length).mapToObj(ix -> String.format("%02x", digest[ix] & 0xFF))
                .collect(joining());
    } catch (NoSuchAlgorithmException | UnsupportedEncodingException ex) {
        // should never happen since we use standard stuff
        throw new InternalError(ex.getMessage());
    }
}

From source file:org.lexgrid.loader.data.association.AbstractReproducibleIdResolver.java

/**
 * Generate key./*from w w  w  .j ava 2s. c om*/
 * 
 * @param basis the basis
 * 
 * @return the string
 */
protected String generateKey(String... basis) {
    MessageDigest md = null;
    try {
        md = MessageDigest.getInstance("SHA1");
    } catch (NoSuchAlgorithmException e) {
        throw new RuntimeException("Error Creating Key Generator");
    }
    md.reset();
    for (int i = 0; i < basis.length; i++)
        if (basis[i] != null)
            md.update(basis[i].getBytes());
    byte[] bytes = md.digest();
    return String.valueOf(Hex.encodeHex(bytes));
}

From source file:org.omegat.core.team2.impl.HTTPRemoteRepository.java

/**
 * Use SHA-1 as file version./*from  w w  w  .java 2s. c om*/
 */
@Override
public String getFileVersion(String file) throws Exception {
    MessageDigest sha1 = MessageDigest.getInstance("SHA-1");
    sha1.reset();

    // calculate SHA-1
    byte[] buffer = new byte[8192];
    InputStream in = new BufferedInputStream(new FileInputStream(file));
    try {
        while (true) {
            int len = in.read(buffer);
            if (len < 0) {
                break;
            }
            sha1.update(buffer, 0, len);
        }
    } finally {
        in.close();
    }

    // out as hex
    Formatter formatter = new Formatter();
    try {
        for (byte b : sha1.digest()) {
            formatter.format("%02x", b);
        }
        return formatter.toString();
    } finally {
        formatter.close();
    }
}

From source file:com.lewischooman.utils.Digester.java

@Override
@SuppressWarnings("CallToPrintStackTrace")
public byte[] digest(String toDigest) {
    MessageDigest mDigest;
    byte[] inBytes, outBytes = null;

    if (toDigest == null) {
        return null;
    }/* w w w  .  j  a  v  a2  s  .  c  om*/

    try {
        mDigest = MessageDigest.getInstance(this.algorithm);

        mDigest.reset();
        inBytes = toDigest.getBytes(this.charset);
        mDigest.update(inBytes);
        outBytes = mDigest.digest();
    } catch (NoSuchAlgorithmException ex) {
        ex.printStackTrace();
    }
    return outBytes;
}

From source file:no.kantega.kwashc.server.test.InsecureCryptographicStorageTest.java

private String generateHash(String algorithm, String password) {

    try {/*from  w ww. j  a  v a  2  s  .  c  o  m*/
        final MessageDigest messageDigest = MessageDigest.getInstance(algorithm);
        messageDigest.reset();
        messageDigest.update(password.getBytes(Charset.forName("UTF8")));
        final byte[] resultByte = messageDigest.digest();
        return new String(Hex.encodeHex(resultByte));
    } catch (NoSuchAlgorithmException e) {
        //
        return "";
    }
}

From source file:info.pancancer.arch3.utils.Utilities.java

public String digest(String plaintext) {
    String result = null;//from   w  ww .j av  a2 s . com
    MessageDigest m;
    try {
        m = MessageDigest.getInstance("MD5");
        m.reset();
        m.update(plaintext.getBytes(StandardCharsets.UTF_8));
        byte[] digest = m.digest();
        BigInteger bigInt = new BigInteger(1, digest);
        final int radix = 16;
        result = bigInt.toString(radix);
    } catch (NoSuchAlgorithmException e) {
        throw new RuntimeException(e);
    }
    return result;
}