如何使用 pem lib NodeJs 创建证书颁发机构 'CA'?

How to create a Certificate Authority 'CA' using pem lib NodeJs?

使用节点创建 CA

这是使用 OpenSSL 创建证书的方法 OpenSSL Certificate Authority

我试过 pem

This is my closed Issue can't create CSR from private key #244 GitHub

当我尝试生成 CSR

var csrOptions = {
    clientKey: '/root/ca/intermediate/private/client.key.pem',
    clientKeyPassword: '123456',
    hash: 'sha256',
    country: 'US',
    state: 'California',
    locality: 'Mountain View',
    organization: 'Alice Ltd',
    organizationUnit: 'Alice Ltd Web Services',
    commonName: 'pass:client',
}

pem.createCSR( csrOptions , function(err, csr) {
    if (err) {
        throw err
    } else {
        console.log(csr.clientKey)
        console.log(csr.csr)
    }

});

我收到这个错误

/root/sslnode/index2.js:37

throw err ^

% openssl req -new -sha256 -config /root/ca/intermediate/openssl.cnf -key /tmp/54f976cb9cbd0e2dd53b755badb6e6e3fe2256ad -passin file:/tmp/3f4640f1d95ca955f1c44c7f2c4b729347813a5f

unable to load Private Key 140563986715072:error:0906D06C:PEM routines:PEM_read_bio:no start >line:../crypto/pem/pem_lib.c:691:Expecting: ANY PRIVATE KEY

搜索后出现错误,clientKey 将密钥作为字符串,而不是路径

clientKey: '/root/ca/intermediate/private/client.key.pem',

clientKey: fs.readFileSync('/root/ca/intermediate/private/client.key.pem'),