Manipulation Signature/Byte Array PHP
Bonjour,
Je cherche à "traduire" un code du Java au PHP.
Le but est d'obtenir une signature d'une chaine de caractères.
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| String s = "1.3.89.5";
byte[] result;
MessageDigest hash = MessageDigest.getInstance ("sha-1");
StringBuffer sig;
hash.reset ();
try {
hash.update (s.getBytes ("US-ASCII"));
} catch (UnsupportedEncodingException e) {
throw new Exception ("Failed : " + e.toString ());
}
result = hash.digest ();
sig = new StringBuffer ();
for (int n = 0; n < result.length; n += 2) {
long ch = (((new Byte (result[n])).longValue () & 0xff) >> 2) % 36;
sig.append (Long.toString (ch, 36););
}
String result = sig.toString (); |
J'ai besoin de faire la même chose mais en PHP.
J'ai essayé :
Code:
1 2 3 4 5 6 7 8
| $bytes = array();
for($i = 0; $i < strlen($input); $i++){
$bytes[] = ord($input[$i]);
}
$sha = sha1($bytes);
for ($n = 0; $n < sizeof($sha); $n += 2) {
//$tmp = ;
} |
Mais aucune idée comment continuer...