Game Development Reference
In-Depth Information
On this page, you will see the MD5 class for C# script and JavaScript that is writen by
Mathew Wegner. Go to JavaScript and copy the code and paste it in the MD5.js script that
we just created:
#pragma strict
static function Md5Sum(strToEncrypt: String)
{
var encoding = System.Text.UTF8Encoding();
var bytes = encoding.GetBytes(strToEncrypt);
// encrypt bytes
var md5 = System.Security.Cryptography.MD5CryptoServiceProvider();
var hashBytes:byte[] = md5.ComputeHash(bytes);
// Convert the encrypted bytes back to a string (base 16)
var hashString = "";
for (var i = 0; i < hashBytes.Length; i++)
{
hashString += System.Convert.ToString(hashBytes[i], 16).
PadLeft(2, "0"[0]);
}
return hashString.PadLeft(32, "0"[0]);
}
This script will allow us to encrypt our string with the MD5 encrypion.
We can use #pragma strict in the Unity JavaScript to tell Unity to
disable the dynamics typing var name = 5 and force us to use the staic
typing var name : int = 5 . This will also make it easy for us to debug
because if we forgot to use the staic typing, Unity will give us an error when
the script is being compiled.
 
Search WWH ::




Custom Search