Using IBM i? Need to create Excel, CSV, HTML, JSON, PDF, SPOOL reports? Learn more about the fastest and least expensive tool for the job: SQL iQuery.
The iQuery.MD5_XXXX() UDF create the Message Digest Hash ("MD5") for the input value. The result is a 16-byte message digest that is unique for the input value. Changing even one bit of any bytes of the input string generates an entirely different message digest result.
UDF | Return Type | Description |
MD5_HASH | varchar(32) | The message digest is converted from the 16-byte value into a 32-byte hexadecimal value. The reason is that the 32-byte values is text friendly while the 16-byte message digest is considered "binary" data. |
MD5_BINARY | varbinary(16) | The message digest is returned as it binary 16-byte format. Note that unreadable characters may be returned and this value should only be stored and/or processed, and should not be displayed or printed as it will send low-level binary data to the output device. |
The MD5_XXXX functions convert the input string from the job CCSID into UTF-8 (CCSID 1208) and then apply the MD5 hash to that data. This is to keep the MD5 results consistent between operating system platforms. For example all MD5 Hash results on Windows and Apple Mac OS will be in ASCII. the iQuery MD5 Hash produces results consistent with those ASCII platforms, by converting the EBCDIC input value into UTF-8 before processing it with the ND5 algorithm.
iQuery.md5_hash( input-value varchar(4096) );
The input-value is limilted to 4096 and this is an abritrary length since most MD5 Hash routines are used to obscure passwords, email addresses, and credit card codes. The result is always the 32-byte MD5 hash in hexadecimal format (for MD5_HAS) or the 16-byte binary form (for MD5_BINARY). But the parameter is the same for both.
exec sql values iQuery.md5_hash( :pwd ) INTO :pwdHash;
exec sql select 1 into :Found from webUserDB
WHERE usrPwd = iQuery.MD5_Binary( :pwd )
FETCH FIRST ROW ONLY;
if (sqlState < '02000' and found = 1); // Password matches! :)
// continue normally
else;
// password failed, try again?
endif;