【发布时间】:2014-10-02 14:43:06
【问题描述】:
我正在尝试通过 PHP 生成 CSR。但是 CA 一直拒绝我的 CSR,因为他们说它不是 2048 位并且不受密码保护。但是当我查看函数 openssl_csr_new() 的 PHP 文档时,我找不到怎么做?
我当前的代码:
$dn = array(
'countryName' => $countryName,
'stateOrProvinceName' => $stateOrProvinceName,
'localityName' => $localityName,
'organizationName' => $organizationName,
'commonName' => $commonName,
'emailAddress' => $emailAddress
);
if(!empty($organizationalUnitName))
$dn['organizationalUnitName'] = $organizationalUnitName;
$csrSettings = array('private_key_bits' => 2048, 'private_key_type' => OPENSSL_KEYTYPE_RSA, 'encrypt_key' => true);
// Generate a new private (and public) key pair
$privkey = openssl_pkey_new($csrSettings);
// Generate a certificate signing request
$csr = openssl_csr_new($dn, $privkey, $csrSettings);
openssl_csr_export($csr, $csrout);
openssl_pkey_export($privkey, $pkeyout);
我做错了什么?
----- 更新代码:--------
$dn = array(
'countryName' => $countryName,
'stateOrProvinceName' => $stateOrProvinceName,
'localityName' => $localityName,
'organizationName' => $organizationName,
'commonName' => $commonName,
'emailAddress' => $emailAddress
);
if(!empty($organizationalUnitName))
$dn['organizationalUnitName'] = $organizationalUnitName;
$csrSettings = array('private_key_bits' => 2048, 'private_key_type' => OPENSSL_KEYTYPE_RSA, 'encrypt_key' => true);
// Generate a new private (and public) key pair
$privkey = openssl_pkey_new($csrSettings);
// Generate a certificate signing request
openssl_pkey_export($privkey, $pkeyout, 'test 1235 aaaaa');
$csr = openssl_csr_new($dn, $pkeyout, $csrSettings);
openssl_csr_export($csr, $csrout);
【问题讨论】:
-
您需要输入密码作为 openssl_pkey_export() 的第三个参数,我认为这应该在您生成密码后立即完成,否则所有其他功能将使用不受密码保护的功能.
-
谢谢,但这并不能解决问题。仍然保持相同的错误。现在的代码是:
$csrSettings = array('private_key_bits' => 2048, 'private_key_type' => OPENSSL_KEYTYPE_RSA, 'encrypt_key' => true); // Generate a new private (and public) key pair $privkey = openssl_pkey_new($csrSettings); // Generate a certificate signing request openssl_pkey_export($privkey, $pkeyout, 'test 1235 aaaaa'); $private_key = $pkeyout; $csr = openssl_csr_new($dn, $pkeyout, $csrSettings); openssl_csr_export($csr, $csrout); -
尝试更新您的问题。我看不懂。
-
据我所知,您无法使用密码保护您的 CSR。请参阅 RFC 2986,Certification Request Syntax Specification。您可以为其添加密码作为属性,但密码用于将来撤销已签名的证书。
-
原来我正在使用的经销商有一个错误..所有方法都工作正常......