Enhancement to ActionScript 3 SHA-1 class

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.

About Josh Tynjala

Josh Tynjala is a frontend developer, open source contributor, bowler hat enthusiast, and karaoke addict. You might be familiar with his project, Feathers UI, an open source user interface library for Starling Framework that is included in the Adobe Gaming SDK.

Discussion

  1. darron

    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!

  2. Pingback: Introducing Torrent Utility, an Apollo application » Zeus Labs

  3. Josh Tynjala

    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.