Tuesday, October 12, 2004
SHA1 ActionScript 2.0 class
If you want data integrity you usually use message digest algorithms like MD5 or SHA1. Flex does not provide built-in message digest functionality so I throw this one in: an ActionScript 2.0 implementation of the Secure Hash Algorithm SHA1 based on the JavaScript implementation by Paul Johnston distributed under the BSD License. Basically, I just wrapped the functionality into static methods and added implicit getters/setters for property access (btw, the class also works in plain Flash MX 2004 projects). Usage is quite straightforward: just add the class package to the [flexcontext]/WEB-INF/flex/user_classes directory and you're set.
The most useful methods are
- static de.richinternet.crypto.SHA1.encode(message:String):String - returns a 40 byte hexadecimal message digest (lower case hex chars by default)
- static de.richinternet.crypto.SHA1.test(Void):Boolean - return true if the VM (i.e. the Flash Player) works ok
To change the default setting for the output format of the hexadecimal message digest use
- static de.richinternet.crypto.SHA1.upperCaseHex:Boolean - set to true to force upper case output, default is false
There are some additional methods and properties (e.g. base64 output) which I'll document if time permits. Otherwise: Just check the source code for further information :)
Download class package: SHA1-v1.0.zip
Download sample MXML file: digest.zip
Dirk.
Comments
You could have saved yourself some time and use the SHA-1 ( or MD5 / TEA / AES / RSA / ROT13 ) classes from http://www.meychi.com/archive/000021.php :)
Posted By Owen van Dijk / Posted At 10/12/04 12:57 PM
Hi there,
Thanks for the great code! I just thought I'd let you know that it doesn't work when compiled with MTASC, although it's quite an easy fix. More information about the solution here :
http://www.sebleedelisle.com/?p=91
thanks again!
Seb
Posted By Seb Lee-Delisle / Posted At 3/10/07 12:16 PM