Here you can find the source of digest(String digest, byte[] data)
Parameter | Description |
---|---|
data | Data to digest |
private static byte[] digest(String digest, byte[] data)
//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()); } } }