1

我只是想知道如何使用 php 创建一个只有预先计算的公钥值的公钥证书。输入公钥和剩余值后,我将使用我自己的 ca 证书签署此证书。谢谢!

4

1 回答 1

2

X.509 证书有一个主题和一个颁发者。如果您只有主题的公钥,您仍然可以使用 CA 的私钥创建 CA 签名证书。使用phpseclib,一个纯 PHP X.509 实现...

<?php
include('File/X509.php');
include('Crypt/RSA.php');

// load private key for issuer / CA
$CAPrivKey = new Crypt_RSA();
$CAPrivKey->loadKey('...');

// load public key for subject
$pubKey = new Crypt_RSA();
$pubKey->loadKey('...');
$pubKey->setPublicKey();

// create the DN for the subject
$subject = new File_X509();
$subject->setDN('...');
$subject->setPublicKey($pubKey);

// create the DN for the issuer
// (the DN can be loaded from another X.509 cert too)
$issuer = new File_X509();
$issuer->setPrivateKey($CAPrivKey);
$issuer->setDN('...');

$x509 = new File_X509();
$x509->setStartDate('-1 month');
$x509->setEndDate('+1 year');

$result = $x509->sign($issuer, $subject);
echo $x509->saveX509($result);
?>
于 2013-02-15T20:53:56.960 回答