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:com.modoop.core.security.utils.Digests.java

/**
 * , ?md5sha1.//  w ww  .j  av a2 s  . com
 */
private static byte[] digest(byte[] input, String algorithm, byte[] salt, int iterations) {
    try {
        MessageDigest digest = MessageDigest.getInstance(algorithm);

        if (salt != null) {
            digest.update(salt);
        }

        byte[] result = digest.digest(input);

        for (int i = 1; i < iterations; i++) {
            digest.reset();
            result = digest.digest(result);
        }
        return result;
    } catch (GeneralSecurityException e) {
        throw ExceptionUtils.unchecked(e);
    }
}

From source file:com.topsem.common.security.utils.Digests.java

/**
 * , ?md5sha1.//from   w w w  . j av a 2  s .  c om
 */
private static byte[] digest(byte[] input, String algorithm, byte[] salt, int iterations) {
    try {
        MessageDigest digest = MessageDigest.getInstance(algorithm);

        if (salt != null) {
            digest.update(salt);
        }

        byte[] result = digest.digest(input);

        for (int i = 1; i < iterations; i++) {
            digest.reset();
            result = digest.digest(result);
        }
        return result;
    } catch (GeneralSecurityException e) {
        throw Throwables.propagate(e);
    }
}

From source file:apm.common.security.Digests.java

/**
 * , ?md5sha1./*from  w w  w . jav a  2  s .  c  o m*/
 */
private static byte[] digest(byte[] input, String algorithm, byte[] salt, int iterations) {
    try {
        MessageDigest digest = MessageDigest.getInstance(algorithm);

        if (salt != null) {
            digest.update(salt);
        }

        byte[] result = digest.digest(input);

        for (int i = 1; i < iterations; i++) {
            digest.reset();
            result = digest.digest(result);
        }
        return result;
    } catch (GeneralSecurityException e) {
        throw Exceptions.unchecked(e);
    }
}

From source file:org.crusoe.util.security.Digests.java

/**
 * , ?md5sha1.// w ww .  ja v a 2s  .c  o  m
 */
private static byte[] digest(byte[] input, String algorithm, byte[] salt, int iterations) {
    try {
        MessageDigest digest = MessageDigest.getInstance(algorithm);

        if (salt != null) {
            digest.update(salt);
        }

        byte[] result = digest.digest(input);

        for (int i = 1; i < iterations; i++) {
            digest.reset();
            result = digest.digest(result);
        }
        return result;
    } catch (GeneralSecurityException e) {
        // throw Exceptions.unchecked(e);
    }
    return null;
}

From source file:com.jkoolcloud.tnt4j.streams.utils.WmqUtils.java

/**
 * Generates a new unique message signature. This signature is expected to be used for creating a new message
 * instance, and is intended to uniquely identify the message regardless of which application is processing it.
 * <p>/*from  www  .jav a 2s  .c  o m*/
 * It is up to the individual stream to determine which of these attributes is available/required to uniquely
 * identify a message. In order to identify a message within two different transports, the streams for each
 * transport must provide the same values.
 *
 * @param _msgDigest
 *            message type
 * @param elements
 *            elements array to calculate signature
 * @return unique message signature
 */
public static String computeSignature(MessageDigest _msgDigest, Object... elements) {
    _msgDigest.reset();

    if (elements != null) {
        for (Object element : elements) {
            if (element instanceof MessageType) {
                _msgDigest.update(String.valueOf(((MessageType) element).value()).getBytes());
            } else if (element instanceof byte[]) {
                _msgDigest.update((byte[]) element);
            } else if (element instanceof String) {
                _msgDigest.update(((String) element).trim().getBytes());
            } else if (element.getClass().isEnum()) {
                _msgDigest.update(((Enum<?>) element).name().getBytes());
            } else {
                String elemStr = Utils.toString(element);
                _msgDigest.update(elemStr.trim().getBytes());
            }
        }
    }

    return Utils.base64EncodeStr(_msgDigest.digest());
}

From source file:com.myb.portal.util.Digests.java

/**
 * , ?md5sha1./*www. j  a  v  a2s  .  c  o  m*/
 */
private static byte[] digest(byte[] input, String algorithm, byte[] salt, int iterations) {
    try {
        MessageDigest digest = MessageDigest.getInstance(algorithm);

        if (salt != null) {
            digest.update(salt);
        }

        byte[] result = digest.digest(input);

        for (int i = 1; i < iterations; i++) {
            digest.reset();
            result = digest.digest(result);
        }
        return result;
    } catch (GeneralSecurityException e) {
        //         throw Exceptions.unchecked(e);
    }
    return salt;
}

From source file:com.thinkgem.jeesite.modules.sso.util.Digests.java

/**
 * , ?md5sha1.//w  w  w . java2 s .  c om
 */
private static byte[] digest(byte[] input, String algorithm, byte[] salt, int iterations) {
    try {
        MessageDigest digest = MessageDigest.getInstance(algorithm);

        if (salt != null) {
            digest.update(salt);
        }

        byte[] result = digest.digest(input);

        for (int i = 1; i < iterations; i++) {
            digest.reset();
            result = digest.digest(result);
        }
        return result;
    } catch (GeneralSecurityException e) {
        return "".getBytes();
    }
}

From source file:org.voltdb.hadoop.Digester.java

/**
 * Generate a MD5 digest from the given content
 *
 * @param aContent/*  ww w . j  a  v  a  2  s  .c  o m*/
 *            a {@code byte[]} array
 * @return an {@code byte[]} array of size 16 (128 bits)
 * @throws DigesterException
 *             upon failed cryptographic operation
 */
public final static byte[] digestMD5(byte[] aContent) throws DigestException {
    if (aContent == null)
        return null;

    MessageDigest md = null;
    try {
        md = MessageDigest.getInstance(DIGEST_ALGORITHM);
    } catch (NoSuchAlgorithmException e) {
        throw new DigestException("generating signature", e);
    }
    md.reset();
    return md.digest(aContent);
}

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

/**
 * , ?md5sha1.//from  www.j a v  a  2 s .  c om
 */
private static byte[] digest(byte[] input, String algorithm, byte[] salt, int iterations) {
    try {
        MessageDigest digest = MessageDigest.getInstance(algorithm);

        if (salt != null) {
            digest.update(salt);
        }

        byte[] result = digest.digest(input);

        for (int i = 1; i < iterations; i++) {
            digest.reset();
            result = digest.digest(result);
        }
        return result;
    } catch (GeneralSecurityException e) {
        throw ExceptionHelper.unchecked(e);
    }
}

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

/**
 * , ?md5sha1.// w  w  w  .  j a  v a 2  s .co m
 */
private static byte[] digest(byte[] input, String algorithm, byte[] salt, int iterations) {
    try {
        MessageDigest digest = MessageDigest.getInstance(algorithm);

        if (salt != null) {
            digest.update(salt);
        }

        byte[] result = digest.digest(input);

        for (int i = 1; i < iterations; i++) {
            digest.reset();
            result = digest.digest(result);
        }
        return result;
    } catch (GeneralSecurityException e) {
        throw ExceptionUtil.unchecked(e);
    }
}