我在NodeJ中运行服务器,其证书将作为字符串存储在DB中(出于安全目的)。我想验证它和它的失效日期,我该怎么做?
我查看了加密'但我找不到可以做到这一点的方法。
例如:
-----BEGIN CERTIFICATE-----
MIIDNTCCAh2gAwIBAgIUJqrw/9EDZbp4DExaLjh0vSAHyBgwDQYJKoZIhvcNAQEL
BQAwFjEUMBIGA1UEAxMLbXl2YXVsdC5jb20wHhcNMTcxMjA4MTkyMzIwWhcNMjcx
MjA2MTkyMzQ5WjAWMRQwEgYDVQQDEwtteXZhdWx0LmNvbTCCASIwDQYJKoZIhvcN
AQEBBQADggEPADCCAQoCggEBAKY/vJ6sRFym+yFYUneoVtDmOCaDKAQiGzQw0IXL
BT55jevSPVVu
-----END CERTIFICATE-----
答案 0 :(得分:1)
使用包x509解决了该问题。
https://www.npmjs.com/package/x509
const x509 = require('x509');
var cert = x509.parseCert(__dirname + '/certs/nodejitsu.com.crt');
/*
cert = { subject:
{ countryName: 'US',
postalCode: '10010',
stateOrProvinceName: 'NY',
localityName: 'New York',
streetAddress: '902 Broadway, 4th Floor',
organizationName: 'Nodejitsu',
organizationalUnitName: 'PremiumSSL Wildcard',
commonName: '*.nodejitsu.com' },
issuer:
{ countryName: 'GB',
stateOrProvinceName: 'Greater Manchester',
localityName: 'Salford',
organizationName: 'COMODO CA Limited',
commonName: 'COMODO High-Assurance Secure Server CA' },
notBefore: Sun Oct 28 2012 20:00:00 GMT-0400 (EDT),
notAfter: Wed Nov 26 2014 18:59:59 GMT-0500 (EST),
altNames: [ '*.nodejitsu.com', 'nodejitsu.com' ],
signatureAlgorithm: 'sha1WithRSAEncryption',
fingerPrint: 'E4:7E:24:8E:86:D2:BE:55:C0:4D:41:A1:C2:0E:06:96:56:B9:8E:EC',
publicKey: {
algorithm: 'rsaEncryption',
e: '65537',
n: '.......' } }
*/