Files
pgserver3.0/pgserver/vendor/lpilp/guomi/test/openssl_tsm2.php
annnj-company 130c1026c4 first commit
2026-04-17 18:29:53 +08:00

22 lines
843 B
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
// openssl支持密码对的生成
// 但未支持解签名,证书颁发openssl 1.1.1 版本目前 不支持 sm3withsm2, 因为sm3withsm2的算法与普通的sha256 with ecdsa的椭圆算法不一样
// git上有相关的gmssl或是tassl的基于openssl开发会支持需要安装然后替换掉当前的openssl, 并且将替换的openssl用源码方式编译到PHP中较麻烦
// 操作请参考: http://gmssl.org/docs/php-api.html
// 生成密码对
$config = array(
"private_key_type" => OPENSSL_KEYTYPE_EC,
"curve_name" => "SM2"
);
$sslconf = "/usr/local/php/extras/openssl/openssl.cnf";
$config['config'] = $sslconf;
$prikey = openssl_pkey_new($config);
openssl_pkey_export($prikey, $prikeypem,null,$config);
echo $prikeypem."\n";
$pubkeypem = openssl_pkey_get_details($prikey)["key"];
echo $pubkeypem."\n";