PHP HMAC SHA256 Hashing

大憨熊 提交于 2019-12-05 07:48:42

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!