Java Digest digestEncrypte(byte[] plainText, String algorithm)

Here you can find the source of digestEncrypte(byte[] plainText, String algorithm)

Description

digest Encrypte

License

Open Source License

Declaration

public static String digestEncrypte(byte[] plainText, String algorithm)
            throws NoSuchAlgorithmException, UnsupportedEncodingException 

Method Source Code


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

import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class Main {
    public static String digestEncrypte(byte[] plainText, String algorithm)
            throws NoSuchAlgorithmException, UnsupportedEncodingException {
        MessageDigest md = MessageDigest.getInstance(algorithm);
        md.update(plainText);/* www . j ava  2  s.c o m*/
        byte[] b = md.digest();
        StringBuilder output = new StringBuilder(32);
        for (int i = 0; i < b.length; i++) {
            String temp = Integer.toHexString(b[i] & 0xff);
            if (temp.length() < 2) {
                output.append("0");
            }
            output.append(temp);
        }
        return output.toString();
    }
}

Related

  1. digest(String value, byte[] salt, int iterations)
  2. digest(String value, String algorithm)
  3. digestBased(String text)
  4. digestBySHA256(byte[] source)
  5. digestBytes(String type, byte[]... data)
  6. digestHex(String txt)
  7. digestHmacToBase64(String algorithm, String msg, byte[] privateKey)
  8. digestInit()
  9. digestOperation(String algo, byte[]... content)