I have to update one web app from Java to PHP and I found some hard problems…
The big problem is to convert the SHA1 from Java to PHP because someone before me developed an browser extension that need a particular auth code to work… i can’t change the plugin, i have only to convert the web app from java to php…
This is the code:
private static final byte[] SecretKey;
public static String AuthCode(String url) {
byte[] urlBytes = url.getBytes("US-ASCII");
byte[] concatenated = new byte[SecretKey.length + urlBytes.length];
System.arraycopy(SecretKey, 0, concatenated, 0, SecretKey.length);
System.arraycopy(urlBytes, 0, concatenated, SecretKey.length, urlBytes.length);
byte[] hash = HashTools.calculateHash(concatenated, "SHA1");
return CodecTools.encodeBASE64(hash);
}
static {
SecretKey = new byte[] { 18, -15, -48, 73, 54, -115, 34, -87 };
}
Now, I found very hard convert the SecretKey from byte to something else in php.. because php don’t have byte variable… and i read that sha1 in php is different from java.
In PHP I can’t make a sha1 of a array chars, it want only a String…
(the other stackoverflow answers suggest only how to change Java code to be equal to php.. I need that the PHP code should be equal to Java…)
I hope in someone that help me because I don’t really know Java…
Thanks to all 🙂
Use a simple string as byte container.
for example, if you want to store the secret key:
Now you have the secret key stored in
$secretString.Edit:
the concatenated array would be:
and then