Java MD5 String md5Digest(final String message)

Here you can find the source of md5Digest(final String message)

Description

md Digest

License

Open Source License

Declaration

private static String md5Digest(final String message)
            throws NoSuchAlgorithmException, UnsupportedEncodingException 

Method Source Code

//package com.java2s;
/**/*from   w w  w .  j  a  v a 2s  .c  om*/
 * Copyright (c) 2011 IETF Trust and the persons identified as authors of the
 * code. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, is permitted pursuant to, and subject to the license terms
 * contained in, the Simplified BSD License set forth in Section 4.c of the IETF
 * Trust's Legal Provisions Relating to IETF Documents
 * (http://trustee.ietf.org/license-info).
 */

import java.io.UnsupportedEncodingException;

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

public class Main {
    private static String md5Digest(final String message)
            throws NoSuchAlgorithmException, UnsupportedEncodingException {
        String digest;
        MessageDigest md = MessageDigest.getInstance("MD5");
        byte[] hash = md.digest(message.getBytes("UTF-8"));

        //converting byte array to Hexadecimal String
        StringBuilder sb = new StringBuilder(2 * hash.length);
        for (byte b : hash) {
            sb.append(String.format("%02x", b & 0xff));
        }

        digest = sb.toString();
        return digest;
    }
}

Related

  1. md5AsHexString(String text, String charset)
  2. md5Base64(String str)
  3. md5ByHex(String src)
  4. md5crypt(String s)
  5. md5Digest(final InputStream data)
  6. md5digest(String key)
  7. md5Digest(String s)
  8. md5Digest(String text)
  9. md5Digest(String word)