Here you can find the source of digest(byte[] message, String hash_alg)
Parameter | Description |
---|---|
message | a parameter |
hash_alg | a parameter |
public static byte[] digest(byte[] message, String hash_alg)
//package com.java2s; /* Copyright (C) 2013 Marius C. Silaghi Author: Marius Silaghi: msilaghi@fit.edu Florida Tech, Human Decision Support Systems Laboratory //w w w . j av a2 s . c o m This program is free software; you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation; either the current version of the License, or (at your option) any later version. This program 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 Affero General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; public class Main { private static final boolean DEBUG = false; /** * Compute digest * @param message * @param hash_alg * @return */ public static byte[] digest(byte[] message, String hash_alg) { MessageDigest digest; try { digest = MessageDigest.getInstance(hash_alg); //Cipher.SHA256 } catch (NoSuchAlgorithmException e) { e.printStackTrace(); return null; } if (DEBUG) System.out.println("ECC:digest"); digest.update(message); byte result[] = digest.digest(); return result; } public static byte[] digest(byte[][] messages, String hash_alg) { MessageDigest digest; try { digest = MessageDigest.getInstance(hash_alg); //Cipher.SHA256 } catch (NoSuchAlgorithmException e) { e.printStackTrace(); return null; } if (DEBUG) System.out.println("ECC:digest"); for (int k = 0; k < messages.length; k++) digest.update(messages[k]); byte result[] = digest.digest(); return result; } }