Cryptography Tutorials - Tutorial Addendum - Bulletin Abstract - MD5 Algorithm

arcadegamesios strategygamesios adventuregamesios
 31 December 18:00   

    



    



    

(Continued from antecedent part...)

    



    

Step 5. Output. The capacity in absorber words A, B, C, D are alternate in arrangement with

    

low-order byte first.

    



    

MD5 Accomplishing in Java

    



    

Sun provides MD5 algorithm in Java beneath their JCE ( Java Cryptography Extension) package,

    

which is included in JDK 1.5.

    



    

Sun s accomplishing of MD5 can be accessed through a all-encompassing chic alleged MessageDigest.

    

Here are the capital methods of MessageDigest class:

    



        

  • getInstance("MD5") - Allotment a bulletin abstract item represents a specific accomplishing

        

    of MD5 algorithm from the absence provider, Sun.

        



  •     

  • getProvider() - Allotment the provider name of the accepted object.

        



  •     

  • update(bytes) - Updates the ascribe bulletin by appending a byte arrangement at the end.

        



  •     

  • digest() - Performs MD5 algorithm on the accepted ascribe bulletin and allotment the bulletin digest

        

    as a byte array. This adjustment aswell resets the ascribe bulletin to an abandoned byte string.

        



  •     

  • reset() - Resets the ascribe bulletin to an abandoned byte string.

        



  •     



    



    

Here is a sample Java program to appearance you how to use the MessageDigest chic to accomplish some tests

    

on MD5 algorithms.

    

 

    

/**

    

* JceMd5Test.java

    

* Absorb (c) 2006 by Dr. Yang, http://www.yang.com/

    

*/

    

import java.security.*;

    

class JceMd5Test {

    

accessible changeless abandoned main(String[] a) {

    

try {

    

MessageDigest md = MessageDigest.getInstance("MD5");

    

System.out.println("Message abstract item info: ");

    

System.out.println(" Algorithm = "+md.getAlgorithm());

    

System.out.println(" Provider = "+md.getProvider());

    

System.out.println(" toString = "+md.toString());

    

Cord ascribe = "";

    

md.update(input.getBytes());

    

byte[] achievement = md.digest();

    

System.out.println();

    

System.out.println("MD5(""+input+"") =");

    

System.out.println(" "+bytesToHex(output));

    

ascribe = "abc";

    

md.update(input.getBytes());

    

achievement = md.digest();

    

System.out.println();

    

System.out.println("MD5(""+input+"") =");

    

System.out.println(" "+bytesToHex(output));

    

ascribe = "abcdefghijklmnopqrstuvwxyz";

    

md.update(input.getBytes());

    

achievement = md.digest();

    

System.out.println();

    

System.out.println("MD5(""+input+"") =");

    

System.out.println(" "+bytesToHex(output));

    



    

} bolt (Exception e) {

    

System.out.println("Exception: "+e);

    

}

    

}

    

accessible changeless Cord bytesToHex(byte[] b) {

    

burn hexDigit[] = { 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 ,

    

8 , 9 , A , B , C , D , E , F };

    

StringBuffer buf = new StringBuffer();

    

for (int j=0; j<b.length; j++) {

    

buf.append(hexDigit[(b[j] >> 4) & 0x0f]);

    

buf.append(hexDigit[b[j] & 0x0f]);

    

}

    

acknowledgment buf.toString();

    

}

    

}

    



    

(Continued on next part...)

    



    



    

 


Tags: system, class, provider, message, notes, string, tutorial, tutorials, object

 println, system, input, message, digest, output, algorithm, string, messagedigest, class, bytestohex, update, hexdigit, tostring, getbytes, object, implementation, returns, cryptography, provider, , system out, md5 algorithm, input message, message digest, println bytestohex, println md5, bytestohex output, input getbytes, update input, digest system, println system, update input getbytes, println bytestohex output, bytestohex output input, input getbytes output, buf append hexdigit, empty byte string, tutorials tutorial notes, tutorial notes message, notes message digest, message digest object, cryptography tutorials tutorial,

Share Cryptography Tutorials - Tutorial Addendum - Bulletin Abstract - MD5 Algorithm:
Digg it!   Google Bookmarks   Del.icio.us   Yahoo! MyWeb   Furl  Binklist   Reddit!   Stumble Upon   Technorati   Windows Live   Bookmark

Text link code :
Hyper link code:

Also see ...

Permalink
Article In : Computers & Technology  -  crypto