Java MD5 String md5Digest(String text)

Here you can find the source of md5Digest(String text)

Description

md Digest

License

Apache License

Declaration

public static byte[] md5Digest(String text) 

Method Source Code

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

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

public class Main {
    private static final String MD5_ALGORITHM_NAME = "MD5";

    public static byte[] md5Digest(String text) {
        return digest(MD5_ALGORITHM_NAME, text.getBytes());
    }//from   www  .  j a  v  a2  s.  c  o  m

    public static byte[] md5Digest(byte[] bytes) {
        return digest(MD5_ALGORITHM_NAME, bytes);
    }

    private static byte[] digest(String algorithm, byte[] bytes) {
        return getDigest(algorithm).digest(bytes);
    }

    /**
     * Creates a new {@link MessageDigest} with the given algorithm. Necessary
     * because {@code MessageDigest} is not thread-safe.
     */
    private static MessageDigest getDigest(String algorithm) {
        try {
            return MessageDigest.getInstance(algorithm);
        } catch (NoSuchAlgorithmException ex) {
            throw new IllegalStateException("Could not find MessageDigest with algorithm \"" + algorithm + "\"",
                    ex);
        }
    }
}

Related

  1. md5crypt(String s)
  2. md5Digest(final InputStream data)
  3. md5Digest(final String message)
  4. md5digest(String key)
  5. md5Digest(String s)
  6. md5Digest(String word)
  7. md5DigestPassword(String password)
  8. md5EncriptionPassword(String str)
  9. md5encrypt(String phrase)