Open In App

Node.js x509.checkIssued(otherCert) Method

Last Updated : 01 Feb, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

The x509.checkIssued() is an inbuilt application programming interface of class X509Certificate within crypto module which is used to check if this PEM encoded X509 Certificate issued by the other certificate or not.

Syntax:

const x509.checkIssued(otherCert)

Parameters: This method takes the PEM encoded X509 Certificate as argument.

Return Value: This method returns Boolean value true if and only if this certificate is issued by some other certificate.

How to generate a Public certificate?

Public certificate Open notepad and copy-paste the following key and save the file as 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-----

Example 1:

Filename: index.js

Javascript




// Node.js program to demonstrate the 
// x509.checkIssued() 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'));
 
const x5091 = new X509Certificate(fs.readFileSync('public-cert.pem'));
 
// checking if passed ip address matches with the given one or not
// by using x509.checkIssued() api
const value = x509.checkIssued(x5091)
 
// display the result
if(value)
  console.log("certificate is issued from other certificate")
else
  console.log("certificate is not issued from other certificate")


Run the index.js file using the following command.

node index.js

Output:

certificate is issued from other certificate

Example 2:

Filename: index.js

Javascript




// Node.js program to demonstrate the 
// x509.checkIssued() 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')))
    .checkIssued(new X509Certificate(fs.readFileSync('public-cert.pem'))))
  console.log("certificate is issued from other certificate")
else
  console.log("certificate is not issued from other certificate")


Run the index.js file using the following command.

node index.js

Output:

certificate is issued from other certificate

Reference: https://nodejs.org/dist/latest-v15.x/docs/api/crypto.html#crypto_x509_checkissued_othercert



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads