c5_labsci/web/admin/demo/dyn/ecc_ukey_ad.php
2026-01-27 00:52:00 +08:00

27 lines
933 B
PHP

<?php
namespace web\admin\demo\dyn;
class ecc_ukey_ad {
public static function json_checkecc() {
$post = new \ciy\post();
$pubkey = $post->get('pubkey');
if (empty($pubkey))
return errjson('请填写公钥');
$sign = $post->get('sign');
if (empty($sign))
return errjson('请填写签名');
$hash = $post->get('hash');
if (empty($hash))
return errjson('请填写hash');
require_once PATH_ROOT . '../libs/sm/autoload.php';
$der = base64_decode($pubkey);
$pubkeyBytes = substr($der, 27);
$publicKey = '04' . bin2hex($pubkeyBytes);
$sm2Object = new \Rtgm\sm\RtSm2('base64', true);
$verifyResult = $sm2Object->verifySign($hash, $sign, $publicKey);
$ret['msg'] = $verifyResult ? "php验签结果: 验签成功" : "php验签结果: 验签失败";
return succjson($ret);
}
}