Openssl: how to read a .crt .. file?

I want to read the certifi.crt file using the OpenSSL API (not in commands). I do not know how to do that. If anyone knows, please help me. Thanks.

If you give an example of code that will be very useful.

+4
source share
1 answer

If the extension “.crt” refers to a PEM text file (starts with ----- BEGIN CERTIFICATE ----- followed by base64), then start working with OpenSSL documents here .

Here is some code to get started (link with ssl, for example g ++ ac -lssl):

 #include <stdio.h> #include <openssl/x509.h> #include <openssl/pem.h> int main(int argc, char** argv) { FILE* f = fopen("certifi.crt", "r"); if (f != NULL) { X509* x509 = PEM_read_X509(f, NULL, NULL, NULL); if (x509 != NULL) { char* p = X509_NAME_oneline(X509_get_issuer_name(x509), 0, 0); if (p) { printf("NAME: %s\n", p); OPENSSL_free(p); } X509_free(x509); } } return 0; } 
+4
source

Source: https://habr.com/ru/post/1346708/


All Articles