Reputation: 1817
I am planning to use crc32 checksum to check data integrity on REST API calls. I use a crc32 library from http://www.icana.org.ar/ICANACardRotator/source/nochump/util/zip/CRC32.as
This and php crc32 function are giving different outputs. In as3 I use the below code
var c:crc32 = new crc32();
var arr:ByteArray = new ByteArray();
arr.writeObject("Hello World!");
c.update(arr);
trace(c.getValue());
which gives me 2098676879
in php I use
<?php
$str = crc32("Hello World!");
printf("%u\n",$str);
?>
which outputs 472456355
Can somebody help me telling what is the difference?
Upvotes: 1
Views: 178
Reputation: 5267
ByteArray.writeObject
writes AMF
encoded object into ByteArray
instead of utf string, that's why you got different result. So the solution is to use writeUTFBytes
:
var c:CRC32 = new CRC32();
var arr:ByteArray = new ByteArray();
arr.writeUTFBytes("Hello World!");
c.update(arr);
trace(c.getValue()); //output 472456355
Upvotes: 1