x509.ca 是加密模块中 X509Certificate 类的内置应用程序编程接口,用于检查此 PEM 编码的 X509 证书是否为证书颁发机构 (ca) 证书。
用法:
const x509.ca
参数:此属性不接受任何参数作为参数。
返回值:当且仅当此 PEM 编码的 X509 证书是证书颁发机构 (ca) 证书时,此属性才返回布尔值 true。
- How to generate a Public certificate?
公共证书打开记事本并使用copy-paste和以下 key 并将文件另存为public-cert.pem
-----BEGIN CERTIFICATE----- MIICfzCCAegCCQDxxeXw914Y2DANBgkqhkiG9w0BAQsFADCBgzELMAkGA1UEBhMC SU4xEzARBgNVBAgMCldlc3RiZW5nYWwxEDAOBgNVBAcMB0tvbGthdGExFDASBgNV BAoMC1BhbmNvLCBJbmMuMRUwEwYDVQQDDAxSb2hpdCBQcmFzYWQxIDAeBgkqhkiG 9w0BCQEWEXJvZm9mb2ZAZ21haWwuY29tMB4XDTIwMDkwOTA1NTExN1oXDTIwMTAw OTA1NTExN1owgYMxCzAJBgNVBAYTAklOMRMwEQYDVQQIDApXZXN0YmVuZ2FsMRAw DgYDVQQHDAdLb2xrYXRhMRQwEgYDVQQKDAtQYW5jbywgSW5jLjEVMBMGA1UEAwwM Um9oaXQgUHJhc2FkMSAwHgYJKoZIhvcNAQkBFhFyb2ZvZm9mQGdtYWlsLmNvbTCB nzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEAt/EfcF3FG4TneOBWr4JhOUdyuCXm Dhy5yO3VKtQfPxr+5d0joCSnn/5vYDNSr1MfedZmqVxrXFoMAdPCd71BNmDmeLVi QK61WREtASP0ZhQMoUBT+R3Fpdy0jPS0YoT/fBd96CJCmgsQOS8Tq5IKVeB61MyC kwAQ2Goe0T3sdVkCAwEAATANBgkqhkiG9w0BAQsFAAOBgQATe6ixdAjoV7BSHgRX bXM2+IZLq8kq3s7ck0EZrRVhsivutcaZwDXRCCinB+OlPedbzXwNZGvVX0nwPYHG BfiXwdiuZeVJ88ni6Fm6RhoPtu2QF1UExfBvSXuMBgR+evp+e3QadNpGx6Ppl1aC hWF6W2H9+MAlU7yvtmCQQuZmfQ== -----END CERTIFICATE-----
范例1:
index.js
// Node.js program to demonstrate the
// x509.ca APi
// Importing crypto module
const {X509Certificate} = require('crypto')
// Importing fs module
const fs = require('fs')
// getting object of a PEM encoded X509 Certificate.
const x509 = new X509Certificate(fs.readFileSync('public-cert.pem'));
// checking if this is a Certificate Authority (ca) certificate or not
// by using x509.ca api
const value = x509.ca
// display the result
if(value)
console.log("this is a Certificate Authority (ca) certificate")
else
console.log("this is not a Certificate Authority (ca) certificate")
使用以下命令运行index.js文件。
node index.js
输出:
this is not a Certificate Authority (ca) certificate
范例2:
index.js
// Node.js program to demonstrate the
// x509.ca APi
// Importing crypto module
const {X509Certificate} = require('crypto')
// Importing fs module
const fs = require('fs')
// display the result
if((new X509Certificate(fs.readFileSync('public-cert.pem'))).ca)
console.log("this is a Certificate Authority (ca) certificate")
else
console.log("this is not a Certificate Authority (ca) certificate")
使用以下命令运行index.js文件。
node index.js
输出:
this is not a Certificate Authority (ca) certificate
参考:https://nodejs.org/dist/latest-v15.x/docs/api/crypto.html#crypto_x509_ca
相关用法
- Node.js GM drawLine()用法及代码示例
- Node.js GM drawArc()用法及代码示例
- Node.js GM drawPolyline()用法及代码示例
- Node.js GM drawBezier()用法及代码示例
- Node.js GM drawCircle()用法及代码示例
- Node.js GM drawEllipse()用法及代码示例
注:本文由纯净天空筛选整理自RohitPrasad3大神的英文原创作品 Node.js x509.ca Property。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。