第二十五章 证书申请 / 25.4.2解码证书请求文件

       #include <openssl/pem.h>

       int    main()

       {

              BIO                      *in;

              X509_REQ            *req=NULL,**req2=NULL;

              FILE                     *fp;

              unsigned charbuf[1024],*p;

              int                         len;

      

              in=BIO_new_file("certreq.txt","r");

              req=PEM_read_bio_X509_REQ(in,NULL,NULL,NULL);

              if(req==NULL)

              {

                     printf("DER解码错误!\n");

              }

              else

              {

                     printf("DER解码成功!\n");

              }

              fp=fopen("certreq2.txt","r");

              len=fread(buf,1,1024,fp);

              fclose(fp);

              p=buf;

              req2=(X509_REQ **)malloc(sizeof(X509_REQ *));

              d2i_X509_REQ(req2,&p,len);

              if(*req2==NULL)

              {

                     printf("DER解码错误!\n");

              }

              else

              {

                     printf("DER解码成功!\n");

              }

              X509_REQ_free(*req2);

              free(req2);

              return 0;

       }

       其中certreq.txtPEM格式的证书请求文件,certreq2.txtDER编码格式。