MD5 function

cara pakai

String md5 = MD5.encode("data yang di Encode");

Fungsinya, simpan dengan nama MD5.java

package com.nux.app.util;

import net.rim.device.api.crypto.MD5Digest;

public class MD5 {
	public static String encode(String data) {
		byte[] bytes = data.getBytes();
	    MD5Digest digest = new MD5Digest();
	    digest.update(bytes, 0, bytes.length);
	    int length = digest.getDigestLength();
	    byte[] md5 = new byte[length];
	    digest.getDigest(md5, 0, true);
	    return byteArrayToHexString(md5);
	}
	
	private static String byteArrayToHexString(byte in[])
	    {
		byte ch = 0x00;
		int i = 0;
		if (in == null || in.length <= 0)
	       	{
			return null;
		}
	        String pseudo[] = {"0", "1", "2","3", "4", "5", "6", "7", "8","9", "A", "B", "C", "D", "E", "F"};
	    	StringBuffer out_str_buf = new StringBuffer(in.length * 2);
	    	while (i < in.length)
		{
	        	ch = (byte) (in[i] & 0xF0);
	        	ch = (byte) (ch >>> 4); 
	        	ch = (byte) (ch & 0x0F);
	        	out_str_buf.append(pseudo[ (int) ch]);
	        	ch = (byte) (in[i] & 0x0F);
	        	out_str_buf.append(pseudo[ (int) ch]);
	        	i++;
	    	}
	    	String rslt = new String(out_str_buf);
	    	return rslt;
	    }
}

About iBNuX
Single fighter Developer

2 Responses to MD5 function

  1. De Totty says:

    Kereenn..🙂

  2. Danang says:

    itu baru md5.encode nya ya? terus md5.decode nya mana? …😛

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: