Hi,
I am having a problem sending some score data for my game that I want to stop the average Joe from hacking.
This is what I have:
- concat all my strings into one long hash string
- add a salt string
- make a md5 hash using the bytes of the hash string encoded using utf8
- send an http POST using Content-Type: application/x-www-form-urlencoded
Here is the Java
StringBuffer sb = new StringBuffer( 512 );
sb.append( name );
sb.append( score );
sb.append( SECRET );
DigestMD5 md5 = new DigestMD5();
md5.reset();
md5.update( sb.toString().getBytes( "UTF-8" ) );
String hash = md5.digestString();
sb.append( "&name=" );
sb.append( URLUTF8Encoder.encode( name ) );
sb.append( "&score=" );
sb.append( score );
sb.append( "&hash=" );
sb.append( URLUTF8Encoder.encode( hash ) );
On the other end, the php script takes the data and tries to verify the hash. It doesn’t seem to work for all encodings.
[php]
$name = mysql_real_escape_string( $_POST[‘name’], $db );
$score = mysql_real_escape_string( $_POST[‘score’], $db );
$hash = $_POST[‘hash’];
$hashString = $name.$score.$SECRECT;
$realHash = md5( utf8_encode( $hashString ) );
[/php]
My host is running php 5. Any help would be very much appreciated.