Enhancement to ActionScript 3 SHA-1 class

by Josh Tynjala

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 the Author

Josh Tynjala is an indie game developer, entrepreneur, Flash and Flex mercenary, and bowler hat enthusiast.

Discussion
  1. 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

    posted by mike chambers on 01.09.2007
  2. 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!

    posted by darron on 01.10.2007
  3. Thanks Mike, Darron.

    posted by Josh Tynjala on 01.10.2007
  4. [...] the latest build of Adobe’s corelib, version 0.90, to build the source. The version includes the enhancements to the SHA1 class that I wrote specifically when I needed them for this [...]

    posted by Introducing Torrent Utility, an Apollo application » Zeus Labs on 03.20.2007
  5. Ok then, but what about decoding SHA1 hash?

    posted by Milo on 05.07.2009
  6. 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.

    posted by Josh Tynjala on 05.07.2009
Share Your Thoughts

To display code in comments: <pre>Code here. May be multiline. Format XML with &gt; and &lt; entities.</pre>

Some HTML allowed in comments: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>