Java Digest digest(String value, String algorithm)

Here you can find the source of digest(String value, String algorithm)

Description

digest

License

Apache License

Declaration

private static byte[] digest(String value, String algorithm) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

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

public class Main {
    private final static String CHARSET = "UTF-8";

    private static byte[] digest(String value, String algorithm) {
        if (value == null || "".equals(value.trim())) {
            return null;
        }//ww w .  ja  va2  s  .c  o  m

        byte[] bytes = null;
        try {
            MessageDigest md = MessageDigest.getInstance(algorithm);
            bytes = md.digest(value.getBytes(CHARSET));
        } catch (NoSuchAlgorithmException e) {
            //NOP
        } catch (UnsupportedEncodingException e) {
            //NOP
        }

        return bytes;
    }
}

Related

  1. digest(String text, String algorithm)
  2. digest(String token)
  3. digest(String type, byte[] bytes)
  4. digest(String uri)
  5. digest(String value, byte[] salt, int iterations)
  6. digestBased(String text)
  7. digestBySHA256(byte[] source)
  8. digestBytes(String type, byte[]... data)
  9. digestEncrypte(byte[] plainText, String algorithm)