Different MD5 with as3corelib

丶灬走出姿态 提交于 2019-12-13 02:47:42

问题


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:


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



来源:https://stackoverflow.com/questions/3883688/different-md5-with-as3corelib

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!