string llMD5String(string src, integer nonce)
Performs a RSA Data Security, Inc. MD5
Message-Digest Algorithm on string
(also known as salt). Returns a 32-character hex
string. (128-bit in binary.)
The actual string used for calculating the MD5 checksum is src + ":" + (string)nonce
. Take note of this if you need to check your MD5 hash outside of SL, such as within a server-side script!
llSay(0, llMD5String("Hello, Avatar!", 0)); // returns 112abd47ceaae1c05a826828650434a6
Same string on a completely different system returns the same checksum (when used with the same nonce):
$ echo -n 'Hello, Avatar!:0' | openssl md5
Example usage, with php:
$nonce = 0;
encoded = md5('Hello, Avatar!'.':'.$nonce);
Q & A
Q: Wait, isn't 32 hex characters 512 bits in binary? (32 * 16 = 512)
A: No, because hex is Base 16, and binary Base 2, meaning a hex character is 4 bits. (See the hexadecimal entry.)
Q: What the hell's a "nonce"?
A: In computer security, a "nonce" is a 'number used once'. It is often a random or pseudo-random number issued in an authentication protocol to ensure that old communications cannot be reused in 'repeat attacks'. So if you wanted to have two scripts talking to each other with secure communications, you might want to consider doing something with llFrand (don't use something easily predictable like the time).
Coincidentally, "nonce" is also a good old word that means 'right now' or 'temporarily', as in, "Are we seriously going to hold it together with duct tape and bubble gum?" "For the nonce!" The etymology of the computer security term is unrelated.
Q: What encoding is used?
A: The result is the MD5 hash of the UTF-8 encoded form of the string.
Q: What happens if UTF-16 characters are passed to it?
A: UTF-16 is an encoding, not a type of character. The elements of LSL strings are Unicode characters. When passed to this call (and also presumable to the base64 encoding calls), the characters are encoded as UTF-8. UTF-8 can represent all Unicode characters. For example the INFINITY symbol is Unicode code point U+221E and is encoded in UTF-8 as the three byte sequence 0xE2 0x88 0x9E.