Java Digest digest(String key)

Here you can find the source of digest(String key)

Description

digest

License

Apache License

Declaration

private static String digest(String key) 

Method Source Code


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

import java.security.MessageDigest;

public class Main {
    private static MessageDigest md5Digest = null;

    private static String digest(String key) {
        byte[] bs = md5digest(key);
        return byte2hex(bs);
    }/*from   w ww.jav  a  2 s . co m*/

    public static byte[] md5digest(String key) {
        if (key == null) {
            return null;
        }
        MessageDigest md5;
        try {
            md5 = (MessageDigest) md5Digest.clone();
        } catch (CloneNotSupportedException e) {
            throw new RuntimeException("clone of MD5 not supported", e);
        }
        md5.update(key.getBytes());
        return md5.digest();
    }

    private static String byte2hex(byte[] b) {
        String hs = "";
        String stmp = "";
        for (int n = 0; n < b.length; n++) {
            stmp = (java.lang.Integer.toHexString(b[n] & 0XFF));
            if (stmp.length() == 1) {
                hs = hs + "0" + stmp;
            } else {
                hs = hs + stmp;
            }
        }
        return hs.toUpperCase();
    }
}

Related

  1. digest(String base)
  2. digest(String digest, byte[] data)
  3. digest(String ha1, String ha2, String nonce)
  4. digest(String input, Charset charset)
  5. digest(String input, String algorithm, String encoding)
  6. digest(String message, byte[] salt)
  7. digest(String name, String source)
  8. digest(String orgin, String algorithm)
  9. digest(String password)