Update: My changes have been accepted to corelib. Please download the official release.
Recently, I worked on a project that required me to use the SHA1 class from Adobe’s open source corelib for ActionScript 3. Unfortunately, the currently available class can only create a hash for string data. That’s cool, but limiting. With some surprisingly simple tweaks, I updated the class to work with raw ByteArray data. Now, we’re talking cool, and infinitely more useful!
//a simple string to hash with the original functionality var message:String = "The quick red dog jumped over the lazy fox."; trace(SHA1.hash(message)); //output: 8aa9f4a49d457eb847cb1a2e4f67a4113cdb8bdf //write the same string to a ByteArray var rawMessage:ByteArray = new ByteArray(); rawMessage.writeUTFBytes(message); trace(SHA1.hashBytes(rawMessage)); //output: 8aa9f4a49d457eb847cb1a2e4f67a4113cdb8bdf (it's the same!)
If you haven’t heard, Mike Chambers arecently announced the release of Adobe’s open source ActionScript 3 libraries on Google Code. They’re hoping that this will help encourage more involvement from the developer community. I talked to Mike a while ago about my enhancements, and I’m hoping to get them integrated soon. For now, I wanted to get these changes in people’s hands. You can download the updated code here and use it under the same license terms as the original version.
fyi
I just logged an issue on this:
http://code.google.com/p/as3corelib/issues/detail?id=6&can=2&q=
(and this is the exact reason we moved the libraries to google code).
Nice work.
mike chambers
mesh@adobe.com
Hi Josh,
Thanks for your efforts. I’ve merged your code updates into the Google Code SVN. Very nice of you to write the unit tests along with the code as well!
Thanks Mike, Darron.
Pingback: Introducing Torrent Utility, an Apollo application » Zeus Labs
Ok then, but what about decoding SHA1 hash?
Milo, hash functions usually aren’t meant to be decoded. In fact, they tend to have collisions, so more than one input can produce the same output, but it is rare.