php生成公钥私钥

//生成密钥对
public function getRsaKeys(){
    $opensslConfigPath = "C:\suike\phpStudy\PHPTutorial\Apache\conf\openssl.cnf";
    $config = array(
        "digest_alg" => "sha512",
        "private_key_bits" =>2048,
        "private_key_type" => OPENSSL_KEYTYPE_RSA,
        'config'=> $opensslConfigPath
    );

    //创建密钥对
    $res = openssl_pkey_new($config);
    //生成私钥
    openssl_pkey_export($res, $privkey, null, $config);
    //生成公钥
    $pubKey = openssl_pkey_get_details($res)['key'];
    return [$privkey,$pubKey];
}

猜你喜欢

转载自blog.csdn.net/weixin_41612889/article/details/88824288
今日推荐