MD5 Algorithm
1.Write MD5 Algorithm Program in Java.
import java.security.*; public class Main { public static void main(String[] args) { try { MessageDigest md = MessageDigest.getInstance("MD5"); System.out.println("Message Digest Object Info:"); System.out.println(" * Algorithm = "+ md.getAlgorithm()); System.out.println(" * Provider = "+ md.getProvider()); System.out.println(" * ToString = "+ md.toString()); String input = ""; md.update(input.getBytes()); byte[] output = md.digest(); System.out.println(); System.out.println("MD5(\""+input+"\")= "+bytesToHexa(output)); input = "abc"; md.update(input.getBytes()); output = md.digest(); System.out.println(); System.out.println("MD5(\""+ input + "\")= " +bytesToHexa(output)); input = "abd"; md.update(input.getBytes()); output = md.digest(); System.out.println(); System.out.println("MD5(\""+ input + "\")= " +bytesToHexa(output)); input = "abcdefghijklmnopqrstquvrwxyz"; md.update(input.getBytes()); output = md.digest(); System.out.println(); System.out.println("MD5(\""+ input + "\")= " +bytesToHexa(output)); input = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; md.update(input.getBytes()); output = md.digest(); System.out.println(); System.out.println("MD5(\""+ input + "\")= " +bytesToHexa(output)); } catch(Exception e) { System.out.println("Exception "+ e); }; } private static String bytesToHexa(byte[] b) { char hexDigit[] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'}; StringBuffer buf = new StringBuffer(); for(int i = 0;i<b.length;i++) { buf.append(hexDigit[(b[i]>>4)& 0x0f]); buf.append(hexDigit[b[i] & 0x0f]); } return buf.toString(); } }
Output :
0 Comments
Thanks,To visit this blog.