Generally we need to encode the password in our Applications for security purpose and we can use MD5 for this purpose.
Example - In the below method I'm encoding sting by using MD5
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
/**
* This method encode the provided string
*
* @param text
* @return
*/
public static String MD5ToString(String salt)
{
MessageDigest md = null;
try
{
md = MessageDigest.getInstance("MD5");
}
catch (NoSuchAlgorithmException e)
{
e.printStackTrace();
}
md.update(salt.getBytes());
byte byteData[] = md.digest();
StringBuffer sb = new StringBuffer();
for (int i = 0; i < byteData.length; i++)
sb.append(Integer.toString((byteData[i] & 0xff) + 0x100, 16).substring(1));
return sb.toString();
}
Hope this will help you :)
0 Comment(s)