从私钥生成CSR密钥

时间:2018-08-21 12:17:55

标签: php ssl certificate csr

我需要根据私钥/证书生成CSR密钥

执行此操作时出现错误

  

openssl_csr_new():dn:add_entry_by_NID 48->(失败;检查错误   非法字符的string_mask OpenSSL选项的队列和值   被报告)test.php(33)

$dn = [
    'commonName'            => '123@-1552-21',// 'func_id@activationcode',
    'organizationalUnitName'=> 'test',
    'organizationName'      => 'test',
    'localityName'          => 'DK',
    'stateOrProvinceName'   => 'DK',
    'countryName'           => 'DK',
    'emailAddress'          => ''
];

$csr = [
    'private_key_bits'  => 2048,
    'private_key_type'  => OPENSSL_KEYTYPE_RSA,
    'encrypt_key'       => true
];

$private_key = openssl_pkey_get_private('./1_0010444508001.pem');

$csr = openssl_csr_new($dn, $private_key, [
    'digest_alg' => 'sha256'
]);

openssl_csr_export($csr, $csrout);
openssl_pkey_export($private_key, $pkeyout, '');

echo $csrout . "\n" . $pkeyout;

1 个答案:

答案 0 :(得分:1)

  

openssl_csr_new():dn:add_entry_by_NID 48->(失败;如果报告了非法字符,请检查错误队列和string_mask OpenSSL选项的值)test.php(33)

问题不是私钥,但问题出在dn中。它抱怨说将具有NID 48的属性添加到CSR中存在问题。 NID 48 is the NID for emailAddress,因此它抱怨该字段的内容。看起来它不应为空。