I want to use MessageDigest
to get a MD5 hash, but I get an error.
import java.security.MessageDigest;
public class dn {
public static void main(
In addition to other answers here
Certain algorithms would not be available with some JVM
To make it truly portable application you should do this
public boolean isMDAvailable(String s)
{
boolean success=true;
try{MessageDigest.GetInstance(s);}
catch(NoSuchAlgorithmException x)
{
success=false;
}
return success;
}
Now you can get any available MD algorithm with this method
public MessageDigest getAvailableMessageDigest()
{
if(isMDAvailable("MD5")==true)return MessageDigest.GetInstance("MD5");
else if(isMDAvailable("MD2")==true)return MessageDigest.GetInstance("MD2");
else if(isMDAvailable("SHA-512")==true)return MessageDigest.GetInstance("SHA-512");
else return null;
}