PHP pfx秘密鍵cer公開鍵SHA 256 WithRSA署名チェックアルゴリズム
955 ワード
暗号化署名
復号チェック
//url
//pad
$certs = array();
openssl_pkcs12_read(file_get_contents($url), $certs, $psd);
if(!$certs){
return ;
}
//data
//binarySignature
if (openssl_sign(utf8_encode($data), $binarySignature, $certs['pkey'], OPENSSL_ALGO_SHA256)) {
return bin2hex($binarySignature);
}
復号チェック
$sign_old = ' ';
$str = ‘ ’;
$cer= file_get_contents( );
$pem = '-----BEGIN CERTIFICATE-----'.PHP_EOL
.chunk_split(base64_encode($cer), 64, PHP_EOL)
.'-----END CERTIFICATE-----'.PHP_EOL;
$pubkeyid = openssl_get_publickey($pem);
$len = strlen($sign_old );
$signature= pack("H" . $len, $sign_old );
$mark = (bool)openssl_verify(
$str,
$signature,
$pubkeyid,
OPENSSL_ALGO_SHA256
);
if($mark){
var_dump($str);
}