问题
im trying to recreate a script from Java to PHP
Usually in php we do hash_mac('sha256',string,key) But the generated signature in php doesnt match the java one...
Here is the java algo:
Mac localMac = getValidMac();
localMac.init(new SecretKeySpec(str1.getBytes("UTF-8"), localMac.getAlgorithm()));
byte[] arrayOfByte = localMac.doFinal(paramString.getBytes());
BigInteger localBigInteger = new BigInteger(1, arrayOfByte);
String str4 = String.format("%0" + (arrayOfByte.length << 1) + "x", new Object[] { localBigInteger });
str3 = str4;
return str3;
Is there anything different in Java appending some strings to the key?
来源:https://stackoverflow.com/questions/13872399/php-hmac-sha256-hashing