1. <tfoot id='p6Pps'></tfoot>

      <small id='p6Pps'></small><noframes id='p6Pps'>

        • <bdo id='p6Pps'></bdo><ul id='p6Pps'></ul>

        <legend id='p6Pps'><style id='p6Pps'><dir id='p6Pps'><q id='p6Pps'></q></dir></style></legend>
        <i id='p6Pps'><tr id='p6Pps'><dt id='p6Pps'><q id='p6Pps'><span id='p6Pps'><b id='p6Pps'><form id='p6Pps'><ins id='p6Pps'></ins><ul id='p6Pps'></ul><sub id='p6Pps'></sub></form><legend id='p6Pps'></legend><bdo id='p6Pps'><pre id='p6Pps'><center id='p6Pps'></center></pre></bdo></b><th id='p6Pps'></th></span></q></dt></tr></i><div id='p6Pps'><tfoot id='p6Pps'></tfoot><dl id='p6Pps'><fieldset id='p6Pps'></fieldset></dl></div>
      1. 如何使用 openssl 从 PKCS7.p7b 证书文件中读取证书文件?

        How to Read the certificates file from the PKCS7.p7b certificate file using openssl?(如何使用 openssl 从 PKCS7.p7b 证书文件中读取证书文件?)
        <legend id='KIsEg'><style id='KIsEg'><dir id='KIsEg'><q id='KIsEg'></q></dir></style></legend>
        <tfoot id='KIsEg'></tfoot>

                <tbody id='KIsEg'></tbody>

              <i id='KIsEg'><tr id='KIsEg'><dt id='KIsEg'><q id='KIsEg'><span id='KIsEg'><b id='KIsEg'><form id='KIsEg'><ins id='KIsEg'></ins><ul id='KIsEg'></ul><sub id='KIsEg'></sub></form><legend id='KIsEg'></legend><bdo id='KIsEg'><pre id='KIsEg'><center id='KIsEg'></center></pre></bdo></b><th id='KIsEg'></th></span></q></dt></tr></i><div id='KIsEg'><tfoot id='KIsEg'></tfoot><dl id='KIsEg'><fieldset id='KIsEg'></fieldset></dl></div>

              <small id='KIsEg'></small><noframes id='KIsEg'>

              • <bdo id='KIsEg'></bdo><ul id='KIsEg'></ul>
                  本文介绍了如何使用 openssl 从 PKCS7.p7b 证书文件中读取证书文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在获取 PKCS7 文件 (p7b).我想读取文件内容并以X509结构提取证书.

                  I am getting PKCS7 file (p7b). I want to read the content of the file and extract certificate in X509 structure.

                  如何使用 openssl 库从 PKCS 容器访问单个证书?

                  How can I access individual Certificate from the PKCS container using openssl library?

                  推荐答案

                  我使用了以下程序:

                  #include <stdio.h>
                  #include <openssl/pkcs7.h>
                  #include <openssl/x509.h>
                  #include <openssl/bio.h>
                  #include <openssl/pem.h>
                  
                  int main(int argc, char **argv)
                  {
                      PKCS7 *p7 = NULL;
                      BIO *in = BIO_new(BIO_s_file());
                      BIO *out = BIO_new(BIO_s_file());
                      int der = 0; /* Input from DER or PEM ? */
                      int text = 0; /* Dump text or output PEM ? */
                      STACK_OF(X509) *certs = NULL;
                      int i;
                  
                      CRYPTO_malloc_init();                                               
                      ERR_load_crypto_strings();
                      OpenSSL_add_all_algorithms();
                  
                      BIO_set_fp(out, stdout, BIO_NOCLOSE);
                      BIO_read_filename(in, argv[1]);
                      p7 = der ?
                          d2i_PKCS7_bio(in, NULL) :
                          PEM_read_bio_PKCS7(in, NULL, NULL, NULL);
                  
                      i = OBJ_obj2nid(p7->type);
                      if(i == NID_pkcs7_signed) {
                          certs = p7->d.sign->cert;
                      } else if(i == NID_pkcs7_signedAndEnveloped) {
                          certs = p7->d.signed_and_enveloped->cert;
                      }
                  
                      for (i = 0; certs && i < sk_X509_num(certs); i++) {
                          X509 *x = sk_X509_value(certs,i);
                          if(text) {
                              X509_print(out, x);
                          } else {
                              PEM_write_bio_X509(out,x);
                          }
                      }
                  }
                  

                  它基于 openssl-1.0.0d/apps/pkcs7.c 并且很容易编译(在 Linux 或 Mac OS X 上)(前提是您将其另存为 readp7.c):

                  It's based on openssl-1.0.0d/apps/pkcs7.c and it's easily compiled (on Linux or Mac OS X) with (provided you save it as readp7.c):

                  gcc -o readp7 readp7.c -lcrypto
                  

                  您可以使用 openssl 创建文件并像这样读取它们:

                  You can create files with openssl and read them like this:

                  openssl crl2pkcs7 -nocrl -certfile a.crt -certfile b.crt -out test.p7b
                  ./readp7 test.p7b
                  

                  这篇关于如何使用 openssl 从 PKCS7.p7b 证书文件中读取证书文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Unable to access non-const member functions of objects in C++ std::set(无法访问 C++ std::set 中对象的非常量成员函数)
                  How should a size-limited stl-like container be implemented?(应该如何实现大小受限的 stl 类容器?)
                  Constructing std::function argument from lambda(从 lambda 构造 std::function 参数)
                  STL BigInt class implementation(STL BigInt 类实现)
                  Sync is unreliable using std::atomic and std::condition_variable(使用 std::atomic 和 std::condition_variable 同步不可靠)
                  Move list element to the end in STL(在 STL 中将列表元素移动到末尾)
                    <tbody id='qqffg'></tbody>

                    <small id='qqffg'></small><noframes id='qqffg'>

                    <i id='qqffg'><tr id='qqffg'><dt id='qqffg'><q id='qqffg'><span id='qqffg'><b id='qqffg'><form id='qqffg'><ins id='qqffg'></ins><ul id='qqffg'></ul><sub id='qqffg'></sub></form><legend id='qqffg'></legend><bdo id='qqffg'><pre id='qqffg'><center id='qqffg'></center></pre></bdo></b><th id='qqffg'></th></span></q></dt></tr></i><div id='qqffg'><tfoot id='qqffg'></tfoot><dl id='qqffg'><fieldset id='qqffg'></fieldset></dl></div>

                      1. <tfoot id='qqffg'></tfoot>

                          <legend id='qqffg'><style id='qqffg'><dir id='qqffg'><q id='qqffg'></q></dir></style></legend>
                            <bdo id='qqffg'></bdo><ul id='qqffg'></ul>