-
-
Notifications
You must be signed in to change notification settings - Fork 645
Tutorial for parsing X.509 certificate
Kenji Urushima edited this page May 27, 2013
·
1 revision
TOP | DOWNLOADS | TUTORIALS | API REFERENCE | DEMOS
X509 class provides following features:
- read and parse PEM formatted X.509 certificate
- get basic fields
- get subject public key as RSAKey object
PEM formatted X.509 certificate is a plain text such as:
-----BEGIN CERTIFICATE-----
MIIBdTCCAR+gAwIBAgIBBTANBgkqhkiG9w0BAQUFADAaMQswCQYDVQQGEwJVUzEL
MAkGA1UECgwCYTEwHhcNMTMwNTA0MDM0MTQxWhcNMjMwNTA0MDM0MTQxWjAaMQsw
(snip)
CJLP08fOfNBZy+KAIy0GsrNU/3uRViqbuGqAnH9kFFwHQjOAFrAe8XQ=
-----END CERTIFICATE-----
To get basic fields of the certificate:
var c = new X509();
c.readCertPEM("-----BEGIN CERTIFICATE(snip)...");
var hSerial = c.getSerialNumberHex(); // '009e755e" hexadecimal string
var sIssuer = c.getIssuerString(); // '/C=US/O=z2'
var sSubject = c.getSubjectString(); // '/C=US/O=z2'
var sNotBefore = c.getNotBefore(); // '100513235959Z'
var sNotAfter = c.getNotAfter(); // '200513235959Z'
To get subject public key as RSAKey object:
var c = new X509();
c.readCertPEM("-----BEGIN CERTIFICATE(snip)...");
var pubKey = c.subjectPublicKeyRSA; // public key as RSAKey object