zoukankan      html  css  js  c++  java
  • PHP RSA算法 HMAC-SHA1加密算法

    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;
    }
  • 相关阅读:
    我的第一个NHibernate示例
    Div+CSS实现表格滚动,JS隐藏和显示Div例子
    VUE 生命周期
    sql AND和OR
    vcloak 隐藏表达式
    sql 多表联查
    SQL 语句解析
    jenkins 使用
    sql 排序(order by)
    sql 基础查询
  • 原文地址:https://www.cnblogs.com/zhangzhijian/p/6558614.html
Copyright © 2011-2022 走看看