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

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

Description

Hash a given string

License

Open Source License

Parameter

Parameter Description
algorithm a parameter
data a parameter

Declaration

public static byte[] digest(String algorithm, byte[] data) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

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

public class Main {
    /**/*from w  w w  . ja  va 2  s.  c  o  m*/
     * Hash a given string
     * @param algorithm
     * @param data
     * @return
     */
    public static byte[] digest(String algorithm, byte[] data) {
        MessageDigest digest;
        try {
            digest = MessageDigest.getInstance(algorithm);
            byte[] hash = digest.digest(data);
            return hash;
        } catch (NoSuchAlgorithmException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            return null;
        }
    }
}

Related

  1. digest(MessageDigest digest, InputStream data)
  2. digest(MessageDigest method, File f)
  3. digest(Serializable object)
  4. digest(String alg, byte[] plainByte)
  5. digest(String algorithm, byte[] bytes)
  6. digest(String algorithm, String data)
  7. digest(String aValue)
  8. digest(String base)
  9. digest(String digest, byte[] data)