how to convert the Certificate String into X509 structure.?

后端 未结 2 1088
别跟我提以往
别跟我提以往 2020-12-31 11:08

can any one tell me how to convert the string content into X509 structure . i am using openssl to read the X509 Structure.

example : certificate string



        
2条回答
  •  盖世英雄少女心
    2020-12-31 11:31

    You can use this OpenSSL code snippet to load the certificate when provided as a string input:

    #include 
    #include 
    #include 
    
    const unsigned char *data = 
        "-----BEGIN CERTIFICATE-----\n"
        "MIIExDCCA6ygAwIBAgIJAK0JmDc/YXWsMA0GCSqGSIb3DQEBBQUAMIGcMQswCQYD\n"
        /*...*/
        "gRQT0OIU5vXzsmhjqKoZ+dBlh1FpSOX2\n"
        "-----END CERTIFICATE-----";
    
    BIO *bio;
    X509 *certificate;
    
    bio = BIO_new(BIO_s_mem());
    BIO_puts(bio, data);
    certificate = PEM_read_bio_X509(bio, NULL, NULL, NULL);
    

    Hope this helps.

提交回复
热议问题