Java MD5 String md5(String raw)

Here you can find the source of md5(String raw)

Description

md

License

Open Source License

Declaration

public static String md5(String raw) 

Method Source Code


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

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

public class Main {
    public static String md5(String raw) {
        return digest(raw, "MD5");
    }//from  w  w w.j  av  a2 s .  c o m

    private static String digest(String raw, String algorithm) {
        if (raw == null || "".equals(raw))
            return "";
        MessageDigest md;
        try {
            md = MessageDigest.getInstance(algorithm);
        } catch (NoSuchAlgorithmException e) {
            throw new RuntimeException(e);
        }
        md.update(raw.getBytes());
        StringBuilder sb = new StringBuilder();
        for (byte b : md.digest()) {
            String hex = String.format("%02x", b);
            sb.append(hex);
        }
        return sb.toString();
    }
}

Related

  1. md5(String plainText)
  2. Md5(String plainText)
  3. Md5(String plainText)
  4. md5(String plainText)
  5. MD5(String pwd)
  6. MD5(String s)
  7. md5(String s)
  8. md5(String s)
  9. md5(String s)