Tuesday, February 2, 2010

Georgia Potbelly Pigs

Md5 (java.security.MessageDigest)

Hello here I put a code that was looking for some time occupying the API (java.security.MessageDigest) of java to encrypt a string.

---------------------- import


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

{public class Md5

private MessageDigest alg;
private String md5;


/ **

* * @ param message * @ throws NoSuchAlgorithmException

* / public void

md5 (String message) throws NoSuchAlgorithmException { computeDigest (bytes);
} public String


getMd5 () {return md5
;
} public void


setMd5 (String md5) {
this.md5 = md5;

} / ** * Performs
digestion
MD5 algorithm * @ param bytes
* / public void

computeDigest (byte [] bytes) {
String str = "";
alg. ();// reset restores the summary
alg.update (bytes) / / update the summary, using the specified
bytes byte [] hash = Alg.digest ();// complete the calculation of dispersive
code for (int i = 0; i
int v = hash [i] & 0xFF;
if (v
cad + = Integer.toString (v, 16). toUpperCase ()+"";
}

this.setMd5 (CAD);

}}



--------------------- -------------------------------

The way to take the class would be:

Md5 md5 = new Md5 ();
md5.md5 ("Hello World");
md5String = md5.getMd5 String ();
System.out.print ("md5" + md5String)


0 comments:

Post a Comment