Android MD5 Encode md5(String text)

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

Description

md

License

Open Source License

Declaration

public static String md5(String text) 

Method Source Code

//package com.java2s;
/* //from   ww  w .  j  a  v a  2 s.  co m
 * SWRVE CONFIDENTIAL
 * 
 * (c) Copyright 2010-2014 Swrve New Media, Inc. and its licensors.
 * All Rights Reserved.
 * 
 * NOTICE: All information contained herein is and remains the property of Swrve
 * New Media, Inc or its licensors.  The intellectual property and technical
 * concepts contained herein are proprietary to Swrve New Media, Inc. or its
 * licensors and are protected by trade secret and/or copyright law.
 * Dissemination of this information or reproduction of this material is
 * strictly forbidden unless prior written permission is obtained from Swrve.
 */

import android.util.Log;

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

public class Main {
    private static final String LOG_TAG = "SwrveSDK";

    public static String md5(String text) {
        if (text == null) {
            return null;
        } else {
            try {
                byte[] bytesOfMessage = text.getBytes();
                MessageDigest md5 = MessageDigest.getInstance("MD5");
                byte[] hash = md5.digest(bytesOfMessage);

                StringBuilder hexDigest = new StringBuilder();
                for (int i = 0; i < hash.length; i++) {
                    if ((0xFF & hash[i]) < 0x10) {
                        hexDigest.append("0");
                    }
                    hexDigest.append(Integer.toHexString(0xFF & hash[i]));
                }
                return hexDigest.toString();
            } catch (NoSuchAlgorithmException nsae) {
                Log.wtf(LOG_TAG, "Couldn't find MD5 - what a strange JVM",
                        nsae);
                return "";
            }
        }
    }
}

Related

  1. stringGetMD5String(String s)
  2. byteMd5(String plainText, Boolean is16)
  3. getMD5(byte[] source)
  4. md5(String string)
  5. createHMACWithMD5(String source, String key)
  6. encryptByUsingMd5(String passwd)
  7. md5(String input)
  8. isValidMD5String(String md5String)
  9. stringToMD5(String key)