从存储为文件的证书中获取属性

Get the properties from an certificate stored as file

我想在我的网站上显示上传到我的网络服务器上的证书。我考虑过向谁展示它的发行人,直到它有效为止。在 Windows 中,我只需双击它即可查看所有详细信息和属性,但如何使用 javascript 实现此目的?这可能吗?这只是 public 密钥,因此它不受密码保护。

假设证书的路径是 /certs/TestCert.cer
这是我暂时想出的一些虚拟代码,用于简要说明我的目标

function displayCertInfo(path) {
    // get properties here
    $issuedTo = /* get issued to property of the cert stored at path */
    $validUntil = /* get valid until property of the cert stored at path */
    document.write("Issued to " + $issuedTo)
    document.write("Valid until " + $validUntil)
}

displayCertInfo("/certs/TestCert.cer")

证书在 DER 二进制文件或以 base 64 编码的 PEM 文件中使用 ASN.1 表示法编码。.crt 文件可以是 DER 编码或 PEM 编码

您需要使用像forge or pkijs这样的加密库来解码证书内容。这是 forge

的例子
 var cert = pki.certificateFromPem(pem);
 console.log(cert.validity.notAfter);