Skip to content
Related Articles

Related Articles

Improve Article

Node.js x509.fingerprint256 Property

  • Last Updated : 26 Mar, 2021

The x509.fingerprint256 is an inbuilt application programming interface of class X509Certificate within crypto module which is used to get the SHA-256 fingerprint of this certificate.

Syntax:

const x509.fingerprint

Parameters: This property does not accept any arguments as a parameter.

Return Value: This property returns the SHA-256 fingerprint of this 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:

index.js




// Node.js program to demonstrate the  
// x509.fingerprint256 function
  
// 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'));
  
// getting the SHA-256 fingerprint of this certificate.
// by using x509.fingerprint256 function
const value = x509.fingerprint256
  
// display the result
console.log("SHA-256 fingerprint of this certificate :- "
            + value)

Run the index.js file using the following command.

node index.js

Output:

SHA-256 fingerprint of this certificate :- 
77:7B:70:8C:52:C5:C8:02:88:B3:BD:D5:1F:6C:A5:AB:78:
0C:4D:0E:F6:6C:0B:DA:ED:49:8E:06:0E:78:8F:05 

Example 2:

index.js




// Node.js program to demonstrate the  
// x509.fingerprint256 function
  
// Importing crypto module
const {X509Certificate} = require('crypto')
  
// Importing fs module
const fs = require('fs')
  
// display the result
console.log("SHA-256 fingerprint of this certificate :- " +
           ( new X509Certificate(fs.readFileSync('public-cert.pem')))
            .fingerprint256)

Run the index.js file using the following command.

node index.js

Output:

SHA-256 fingerprint of this certificate :-
77:7B:70:8C:52:C5:C8:02:88:B3:BD:D5:1F:6C:A5:AB:
78:0C:4D:0E:F6:6C:0B:DA:ED:49:8E:06:0E:78:8F:05 

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




My Personal Notes arrow_drop_up
Recommended Articles
Page :