by
0
6
290k
1
Top 1% !
Popular
Pearl of Wisdom
Tagged
Specified
OpenSource
Popularity: 3994th place

Published on:

InputName0input
InputType0String
JVMjre5
LanguageJava
LicenseMIT_X11
MethodNamecomputeMD5Hash
OutputTypeString

How to simply compute the MD5 hash of a given string, being sure to have the same results retrieved by HASH method of MS SQL Server

Returns the MD5 hash of the given string
Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
src="https://www.snip2code.com/Embed/113401/How-to-simply-compute-the-MD5-hash-of-a-?startLine=0"></iframe>
Click on the embed code to copy it into your clipboard Width Height
Leave empty to retrieve all the content Start End
public static String computeMD5Hash(String input) { if (isNullOrEmpty(input)) return ""; byte[] bytesOfMessage = null; try { bytesOfMessage = input.getBytes("UTF-16LE"); } catch (UnsupportedEncodingException e) { log.error("Cannot support UTF-8 encoding due to " + e, e); return ""; } MessageDigest md = null; try { md = MessageDigest.getInstance("MD5"); } catch (NoSuchAlgorithmException e) { log.error("Cannot support MD5 algorithm due to " + e, e); return ""; } byte[] thedigest = md.digest(bytesOfMessage); return printHexByteArray(thedigest); }

Other Steps and Solutions

If you want to be updated about similar snippets, Sign in and follow our Channels

blog comments powered by Disqus