Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert MD5 array to String java

Tags:

java

md5

I know that there is a lot of similar topics, but still... can someone provide me a working example of method which generates MD5 String.
I'm currently using MessageDigest, and I'm doing the following to get a string

sun.misc.BASE64Encoder().encode(messageDigest.digest())  

I guess there is some better way to do that.
Thanks in advance!

like image 806
Andrew Avatar asked Sep 20 '10 15:09

Andrew


1 Answers

MessageDigest md = MessageDigest.getInstance("MD5");
byte[] arr = md.digest(bytesOfMessage);
return Base64.getEncoder().encodeToString(arr);

note: md5 is not considered as good hash algorithm anymore, consider choosing SHAs

like image 200
jmj Avatar answered Sep 21 '22 02:09

jmj