当前位置: 首页 > 工具软件 > Php-serial > 使用案例 >

php获取证书编号没有serialNumberHex只有serialNumber处理方法

裴焱
2023-12-01

 php获取证书编号没有serialNumberHex只有serialNumber处理方法

 

function getserialNumberHex($apiclient_cert_path){
        $arr = glob($apiclient_cert_path);
        $cert = '';
        if(!empty($arr)){
            foreach ($arr as $key => $val) {
                $contents = file_get_contents($val);
                $tempArr = openssl_x509_parse($contents);
                $serial = $tempArr['serialNumber'];
                $base = bcpow("2", "32");
                $counter = 100;
                $res = "";
                $val = $serial;
                while($counter > 0 && $val > 0) {
                    $counter = $counter - 1;
                    $tmpres = dechex(bcmod($val, $base)) . "";
                    /* adjust for 0's */
                    for ($i = 8-strlen($tmpres); $i > 0; $i = $i-1) {
                        $tmpres = "0$tmpres";
                    }
                    $res = $tmpres .$res;
                    $val = bcdiv($val, $base);
                }
                if ($counter <= 0) {
                    echo 'Occured failed.';
                    exit;
                }
                return strtoupper($res);
            }
        }else{
            return false;
        }
        
    }

 类似资料: