views:

25

answers:

1

I'm trying to md5 some file with as3corelib, but if I compare the as3 hash with a php one, I get different strings.

That's what I do:

_loader = new URLLoader();
_loader.load( new URLRequest( "image.jpg" ) );
_loader.addEventListener( Event.COMPLETE, completeHandler );

private function completeHandler( event:Event ):void {
       var data:ByteArray = new ByteArray(); 
       data.writeUTFBytes( _loader.data );
       var hash:MD5Stream = new MD5Stream();
       trace(hash.complete(data));
}

I've already googled for this issue, finding this post where a similar thing is discussed (making an hash of a string).

Any idea?

+1  A: 

Try to set the loader dataFormat property to URLLoaderDataFormat.BINARY prior to the load() call:

_loader = new URLLoader();
_loader.dataFormat = URLLoaderDataFormat.BINARY;
_loader.load( new URLRequest( "image.jpg" ) );
_loader.addEventListener( Event.COMPLETE, completeHandler );

private function completeHandler( event:Event ):void {
       var hash:MD5Stream = new MD5Stream();
       trace(hash.complete(_loader.data));
}

Then use directly the _loader.data variable since now it's a ByteArray

Madarco
that did the trick. thanks :)
Alberto M