Package beans;
Import java. Io .*;
Import java. Security .*;
Public class changemd5
{
Private messagedigest currentalgorithm;
Public String computedigest (byte [] B)
{
Try
{
Currentalgorithm = messagedigest. getinstance ("MD5 ");
} Catch (nosuchalgorithmexception e ){}
Currentalgorithm. Reset ();
Currentalgorithm. Update (B );
Byte [] hash = currentalgorithm. Digest ();
String d = "";
For (INT I = 0; I {
Int v = hash [I] & 0xff;
If (v <16) D + = "0 ";
D + = integer. tostring (v, 16). tolowercase ();
}
Return D;
}
}
This sectionCodeYou can use it directly.ProgramIt is actually a bean, and its method name is computedigest (
Byte [] B). The parameter is a byte type variable. If you want to encrypt the string "xiapeng" with MD5 encryption, first set a string-type variable, such as string result = "xiapeng "; in addition, you can use the getbytes () method to convert the type, and then call the beans in JSP to get it OK.