If anyone is interested in calculating MD5 hash values in their Flash files, I've thrown together some code in an ActionScript class for everyone to enjoy. Useful for calculating file checksums, password authentication and so forth.
From the .AS file:
Code:
/* -----------------------------
MD5Hash.as
Creates a class called Hash.MD5Hash used to calculate the MD5 hash value of a given set of data.
Place this file in a subdirectory named Hash in your classpath for ActionScript.
Use 'import Hash.MD5Hash;' to include the .as file
Use 'm = new MD5Hash("a");' to initialize a new instance
Class exports the following functions
// Constructor, takes one string
MD5Hash(s:String)
// Getter/Setter functions
getText():String -- returns string passed to the constructor or setText() function
setText( s:String ):Void -- sets the internal data set to a new value and re-calculates the hash
getHash():String -- returns the last calculated hash value
toString():String -- synonym for getHash()
valueOf():String -- synonym for getHash()
To re-use an existing Hash instance, simply call the setText() function with a new dataset, the hash
value will be re-calculated instantly.
Example:
////// BEGIN EXAMPLE //////
import Hash.MD5Hash;
m = new MD5Hash();
trace( m.getText() + ": " + m.getHash() );
// should return 'd41d8cd98f00b204e9800998ecf8427e'
m.setText(""); // an undefined value is the same as an empty string, should get the same result
trace( m.getText() + ": " + m.getHash() );
// should also return 'd41d8cd98f00b204e9800998ecf8427e'
m.setText("a");
trace( m.getText() + ": " + m.getHash() );
// should return '0cc175b9c0f1b6a831c399e269772661'
m.setText( "The quick brown fox jumps over the lazy dog; what a boring and useless phrase" );
trace( m.getText() + ": " + m.getHash() );
// should return 'f35cbee66b5f212043f5d6a12472ed6c'
////// END EXAMPLE //////
Portions of this code were borrowed from http://userpages.umbc.edu/~mabzug1/cs/md5/md5.html
*/