ºÝºÝߣ

ºÝºÝߣShare a Scribd company logo
KELOMPOK 6
IVAN JOND
JANUARIANTO EMANUEL
ARDIDIY
OKA BAKTI PRATAMA
MUHAMMAD FADDILAH
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
public class DemoMD5
{
private static String convertedToHex(byte[] data)
{
StringBuffer buf = new StringBuffer();
for (int i = 0; i < data.length; i++)
{
int halfOfByte = (data[i] >>> 4) & 0x0F;
int twoHalfBytes = 0;
do
{
if ((0 <= halfOfByte) && (halfOfByte <= 9))
{
buf.append( (char) ('0' + halfOfByte) );
}
else
? buf.append( (char) ('a' + (halfOfByte - 10)) );
}
halfOfByte = data[i] & 0x0F;
} while(twoHalfBytes++ < 1);
}
return buf.toString();
}
public static String MD5(String text)
throws NoSuchAlgorithmException, UnsupportedEncodingException
{
MessageDigest md;
md = MessageDigest.getInstance("MD5");
byte[] md5 = new byte[64];
md.update(text.getBytes("iso-8859-1"), 0, text.length());
md5 = md.digest();
return convertedToHex(md5);
}
}
? import java.util.Scanner;
import java.io.UnsupportedEncodingException;
import java.security.NoSuchAlgorithmException;
public class Password
{
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
String password = " ";
String again = "Y";
while (again.toUpperCase().charAt(0) == 'Y')
{
System.out.print("Enter string: ");
password = scan.nextLine();
try
{
System.out.println("MD5 string: " + DemoMD5.MD5(password));
}
catch (NoSuchAlgorithmException a)
{
a.printStackTrace();
}
? catch (UnsupportedEncodingException a)
{
a.printStackTrace();
}
System.out.print("nRun again?: ");
again = scan.nextLine();
}
System.exit(0);
}
}
? /*===================[output]===================
Enter string: HelloEncrytion
MD5 string: 3226f13a86b23a7ef65656703cd9ce5a
Run again?: y
Enter string: 12345
MD5 string: 827ccb0eea8a706c4c34a16891f84e7b
Run again?: Yes
Enter string: ThisIsKindOfFun
MD5 string: c7cd55c195f83ebfb739960ae8ceb465
Run again?: Ya
Enter string: Good Bye In 2010
MD5 string: 855380d7335697f739aae9d88819ec1f
Run again?: NOPE
==============================================*/
?

More Related Content

Contoh program dari md5

  • 1. KELOMPOK 6 IVAN JOND JANUARIANTO EMANUEL ARDIDIY OKA BAKTI PRATAMA MUHAMMAD FADDILAH
  • 2. import java.io.UnsupportedEncodingException; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; public class DemoMD5 { private static String convertedToHex(byte[] data) { StringBuffer buf = new StringBuffer(); for (int i = 0; i < data.length; i++) { int halfOfByte = (data[i] >>> 4) & 0x0F; int twoHalfBytes = 0; do { if ((0 <= halfOfByte) && (halfOfByte <= 9)) { buf.append( (char) ('0' + halfOfByte) ); } else
  • 3. ? buf.append( (char) ('a' + (halfOfByte - 10)) ); } halfOfByte = data[i] & 0x0F; } while(twoHalfBytes++ < 1); } return buf.toString(); } public static String MD5(String text) throws NoSuchAlgorithmException, UnsupportedEncodingException { MessageDigest md; md = MessageDigest.getInstance("MD5"); byte[] md5 = new byte[64]; md.update(text.getBytes("iso-8859-1"), 0, text.length()); md5 = md.digest(); return convertedToHex(md5); } }
  • 4. ? import java.util.Scanner; import java.io.UnsupportedEncodingException; import java.security.NoSuchAlgorithmException; public class Password { public static void main(String[] args) { Scanner scan = new Scanner(System.in); String password = " "; String again = "Y"; while (again.toUpperCase().charAt(0) == 'Y') { System.out.print("Enter string: "); password = scan.nextLine(); try { System.out.println("MD5 string: " + DemoMD5.MD5(password)); } catch (NoSuchAlgorithmException a) { a.printStackTrace(); }
  • 5. ? catch (UnsupportedEncodingException a) { a.printStackTrace(); } System.out.print("nRun again?: "); again = scan.nextLine(); } System.exit(0); } }
  • 6. ? /*===================[output]=================== Enter string: HelloEncrytion MD5 string: 3226f13a86b23a7ef65656703cd9ce5a Run again?: y Enter string: 12345 MD5 string: 827ccb0eea8a706c4c34a16891f84e7b Run again?: Yes Enter string: ThisIsKindOfFun MD5 string: c7cd55c195f83ebfb739960ae8ceb465 Run again?: Ya Enter string: Good Bye In 2010 MD5 string: 855380d7335697f739aae9d88819ec1f Run again?: NOPE ==============================================*/ ?