php加密javahmac sha1
最近遇到hmac_sha1跨语言加密的问题,只提供给了java加密文件,没提供php的,我用php hmac_sha1内置函数,得到的sig加密结果不同,欢迎高手帮忙提供相对应的php代码,提供的java类如下
欢迎加qq: 847036019
public abstract class coder {
public static final string key_sha = sha;
public static final string key_md5 = md5;
public static final char hexdigits[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'a', 'b', 'c', 'd', 'e', 'f' };
public static final string key_mac = hmacsha1;
public static byte[] decryptbase64(string key) throws exception {
return (new base64decoder()).decodebuffer(key);
}
/**
* 初始化hmac密钥
*/
public static string initmackey() throws exception {
keygenerator keygenerator = keygenerator.getinstance(key_mac);
secretkey secretkey = keygenerator.generatekey(); return encryptbase64(secretkey.getencoded()); } /** * hmac加密 */ public static byte[] encrypthmac(byte[] data, string key) throws exception { secretkey secretkey = new secretkeyspec(decryptbase64(key), key_mac); mac mac = mac.getinstance(secretkey.getalgorithm()); mac.init(secretkey); return mac.dofinal(data); } public static void main(string[] args) { try { string param = ''; string appkey = ''; byte[] bytes = coder.encrypthmac((param).getbytes(utf-8), appkey);//['-115','-101','97','-26','-80','-109','-92','33','-6','71','-122','-64','-17','-29','-101','-53','88','-93','-22','-104'] string sig = new biginteger(bytes).tostring();//-653068794747578802236590292838260814592085857640 system.out.println(sig: + sig); } catch (exception e) { // todo auto-generated catch block e.printstacktrace(); } }} java sig得出来的结果为 -653068794747578802236590292838260814592085857640
php我用相对应的加密即php自带函数
$signature = mhash(mhash_sha1,$sigstr,base64_decode($appkey));
$hash = str_split($signature);
foreach ($hash as $index=>$value) {
if (ord($value)>128) {
$hash[$index] = ord($value)-128*2;
} else {
$hash[$index] = ord($value);
}
}
php得到的ascii数组为$array('-115','-101','97','-26','-80','-109','-92','33','-6','71','-122','-64','-17','-29','-101','-53','88','-93','-22','-104');
请问该php如何处理得到下面的值
-653068794747578802236590292838260814592085857640
java用的是new biginteger(bytes).tostring();php该如何处理