Java Digest digest(String digest, byte[] data)

Here you can find the source of digest(String digest, byte[] data)

Description

Calculates the SHA digest and returns the value as a 16 element byte[] .

License

Open Source License

Parameter

Parameter Description
data Data to digest

Return

digest

Declaration

private static byte[] digest(String digest, byte[] data) 

Method Source Code

//package com.java2s;
/*//from   w  ww .  jav a 2s. c  o  m
 * Copyright 2004 - 2009 Christian Sprajc. All rights reserved.
 *
 * This file is part of PowerFolder.
 *
 * PowerFolder is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation.
 *
 * PowerFolder is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with PowerFolder. If not, see <http://www.gnu.org/licenses/>.
 *
 * $Id: Constants.java 11478 2010-02-01 15:25:42Z tot $
 */

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class Main {
    /**
     * Calculates the SHA digest and returns the value as a 16 element
     * {@code byte[]}.
     *
     * @param data
     *            Data to digest
     * @return digest
     */
    private static byte[] digest(String digest, byte[] data) {
        return getDigest(digest).digest(data);
    }

    /**
     * Returns a MessageDigest for the given {@code algorithm}.
     *
     * @param algorithm
     *            The MessageDigest algorithm name.
     * @return An MD5 digest instance.
     * @throws RuntimeException
     *             when a {@link NoSuchAlgorithmException} is
     *             caught,
     */
    private static MessageDigest getDigest(String algorithm) {
        try {
            return MessageDigest.getInstance(algorithm);
        } catch (NoSuchAlgorithmException e) {
            throw new RuntimeException(e.getMessage());
        }
    }
}

Related

  1. digest(String algorithm, byte[] bytes)
  2. digest(String algorithm, byte[] data)
  3. digest(String algorithm, String data)
  4. digest(String aValue)
  5. digest(String base)
  6. digest(String ha1, String ha2, String nonce)
  7. digest(String input, Charset charset)
  8. digest(String input, String algorithm, String encoding)
  9. digest(String key)