In Java, if I want to compute an MD5 sum, I need to be aware of possible exceptions:
try {
MessageDigest md = MessageDigest.getInstance("MD5");
// Do stuff
} catch (NoSuchAlgorithmException e) {
// Can't happen...
}
However, according to the JVM spec, MD5 must be supported, so the exception should never be thrown. Is there a different access pattern that allows me to write more elegant code?
Instead of MessageDigest
you can use common.apache
DigestUtils
.
This is easy to use and no need to take such long procedure to digest data like MessageDigest
does.
DigestUtils.md5("String to digest");
Go through this Class and follow this documentation
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With