HMAC-SHA1加密算法
function getSignature($str, $key) { $signature = ""; if (function_exists('hash_hmac')) { $signature = base64_encode(hash_hmac("sha1", $str, $key, true)); } else { $blocksize = 64; $hashfunc = 'sha1'; if (strlen($key) > $blocksize) { $key = pack('H*', $hashfunc($key)); } $key = str_pad($key, $blocksize, chr(0x00)); $ipad = str_repeat(chr(0x36), $blocksize); $opad = str_repeat(chr(0x5c), $blocksize); $hmac = pack( 'H*', $hashfunc( ($key ^ $opad) . pack( 'H*', $hashfunc( ($key ^ $ipad) . $str ) ) ) ); $signature = base64_encode($hmac); } return $signature; }
php openssl(SHA1WithRSA) 签名 验签
签名:
public function wjSign($data){ $key = openssl_pkey_get_private(file_get_contents($this->privateKeyPathWJ)); openssl_sign($data, $sign, $key, OPENSSL_ALGO_SHA1); $sign = base64_encode($sign); return $sign; }
验签:
public function wjVerify($data, $sign){ $sign = base64_decode($sign); $key = openssl_pkey_get_public(file_get_contents($this->publicKeyPathWJ)); $result = openssl_verify($data, $sign, $key, OPENSSL_ALGO_SHA1) === 1; return $result; }
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:mmqy2019@163.com进行举报,并提供相关证据,查实之后,将立刻删除涉嫌侵权内容。
长按识别二维码并关注微信
更方便到期提醒、手机管理