#Support for parsing a cert file to Certificate

1 messages · Page 1 of 1 (latest)

calm narwhal
#

I need to read the content of a .cert format file. In java, we can do this as below.

CertificateFactory fac = CertificateFactory.getInstance("X509"); FileInputStream is = new FileInputStream("\\path\\to\\file\\cert.crt"); X509Certificate cert = (X509Certificate) fac.generateCertificate(is); System.out.println("From: " + cert.getNotBefore()); System.out.println("Until: " + cert.getNotAfter());

I need to know that, whether it's possible to do something like this using pure ballerina. (without using java interop)?

rain socket
#

You can use the ballerina/crypto module. For example:

crypto:PublicKey pubKey = check crypto:decodeRsaPublicKeyFromCertFile("path/to/.cert");
io:println(pubKey.certificate?.notBefore);
io:println(pubKey.certificate?.issuer);