• <tfoot id='yCXGF'></tfoot>
  • <legend id='yCXGF'><style id='yCXGF'><dir id='yCXGF'><q id='yCXGF'></q></dir></style></legend>

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

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

      1. 如何在没有 p、q 等的情况下加载 RSA 密钥对

        How to load RSA key pair without p, q, etc(如何在没有 p、q 等的情况下加载 RSA 密钥对)
            • <small id='0rgZt'></small><noframes id='0rgZt'>

              <tfoot id='0rgZt'></tfoot><legend id='0rgZt'><style id='0rgZt'><dir id='0rgZt'><q id='0rgZt'></q></dir></style></legend>
              • <bdo id='0rgZt'></bdo><ul id='0rgZt'></ul>
                  <tbody id='0rgZt'></tbody>
                <i id='0rgZt'><tr id='0rgZt'><dt id='0rgZt'><q id='0rgZt'><span id='0rgZt'><b id='0rgZt'><form id='0rgZt'><ins id='0rgZt'></ins><ul id='0rgZt'></ul><sub id='0rgZt'></sub></form><legend id='0rgZt'></legend><bdo id='0rgZt'><pre id='0rgZt'><center id='0rgZt'></center></pre></bdo></b><th id='0rgZt'></th></span></q></dt></tr></i><div id='0rgZt'><tfoot id='0rgZt'></tfoot><dl id='0rgZt'><fieldset id='0rgZt'></fieldset></dl></div>

                  本文介绍了如何在没有 p、q 等的情况下加载 RSA 密钥对的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我试图找到一种仅使用 n、e、d 将 RSA 密钥对加载到 Openssl 的方法.根据 RSA 的 openssl 文档,这些组件(p、q 等)可以为 NULL,但我设法找到的唯一加载密钥的函数是 i2d_RSAPrivateKey/i2d_RSAPublicKey.不幸的是,这些功能仅适用于 DER 格式的密钥.

                  I'm trying to find a way of loading RSA key pair to Openssl using only n, e, d. According to the openssl documentation for the RSA those components (p, q, etc) can be NULL, but the only function for loading keys I managed to find is i2d_RSAPrivateKey / i2d_RSAPublicKey. Unfortunally these functions work only with keys in DER format.

                  那么除了将它们直接处理到 RSA 结构中之外,还有什么方法可以加载我的密钥 (n, e, d)?

                  So is there any way to load my keys (n, e, d) except coping them directly into the RSA structure?

                  推荐答案

                  ...这些功能仅适用于 DER 格式的密钥.

                  ... these functions work only with keys in DER format.

                  OpenSSL 的 app.c 具有实用程序用来从文件加载密钥的代码(出于实际目的,文件或内存之间没有区别,因为您可以使用不同的 BIO代码>).其转载如下,并提供多种格式.

                  OpenSSL's app.c has the code the utility uses to load keys from a file (for practical purposes, there's no difference between file or memory because you can use a different BIO). Its reproduced below, and it offers a number of formats.

                  那么除了将它们直接处理到 RSA 结构中之外,还有什么方法可以加载我的密钥 (n, e, d)?

                  So is there any way to load my keys (n, e, d) except coping them directly into the RSA structure?

                  您的密钥是什么格式的?

                  What format are your keys in?

                  EVP_PKEY *load_key(BIO *err, const char *file, int format, int maybe_stdin,
                                     const char *pass, ENGINE *e, const char *key_descrip)
                  {
                      BIO *key=NULL;
                      EVP_PKEY *pkey=NULL;
                      PW_CB_DATA cb_data;
                  
                      cb_data.password = pass;
                      cb_data.prompt_info = file;
                  
                      if (file == NULL && (!maybe_stdin || format == FORMAT_ENGINE))
                      {
                          BIO_printf(err,"no keyfile specified
                  ");
                          goto end;
                      }
                  #ifndef OPENSSL_NO_ENGINE
                      if (format == FORMAT_ENGINE)
                      {
                          if (!e)
                              BIO_printf(err,"no engine specified
                  ");
                          else
                          {
                              pkey = ENGINE_load_private_key(e, file,
                                                             ui_method, &cb_data);
                              if (!pkey)
                              {
                                  BIO_printf(err,"cannot load %s from engine
                  ",key_descrip);
                                  ERR_print_errors(err);
                              }
                          }
                          goto end;
                      }
                  #endif
                      key=BIO_new(BIO_s_file());
                      if (key == NULL)
                      {
                          ERR_print_errors(err);
                          goto end;
                      }
                      if (file == NULL && maybe_stdin)
                      {
                  #ifdef _IONBF
                  # ifndef OPENSSL_NO_SETVBUF_IONBF
                          setvbuf(stdin, NULL, _IONBF, 0);
                  # endif /* ndef OPENSSL_NO_SETVBUF_IONBF */
                  #endif
                          BIO_set_fp(key,stdin,BIO_NOCLOSE);
                      }
                      else
                          if (BIO_read_filename(key,file) <= 0)
                          {
                              BIO_printf(err, "Error opening %s %s
                  ",
                                         key_descrip, file);
                              ERR_print_errors(err);
                              goto end;
                          }
                      if (format == FORMAT_ASN1)
                      {
                          pkey=d2i_PrivateKey_bio(key, NULL);
                      }
                      else if (format == FORMAT_PEM)
                      {
                          pkey=PEM_read_bio_PrivateKey(key,NULL,
                                                       (pem_password_cb *)password_callback, &cb_data);
                      }
                  #if !defined(OPENSSL_NO_RC4) && !defined(OPENSSL_NO_RSA)
                      else if (format == FORMAT_NETSCAPE || format == FORMAT_IISSGC)
                          pkey = load_netscape_key(err, key, file, key_descrip, format);
                  #endif
                      else if (format == FORMAT_PKCS12)
                      {
                          if (!load_pkcs12(err, key, key_descrip,
                                           (pem_password_cb *)password_callback, &cb_data,
                                           &pkey, NULL, NULL))
                              goto end;
                      }
                  #if !defined(OPENSSL_NO_RSA) && !defined(OPENSSL_NO_DSA) && !defined (OPENSSL_NO_RC4)
                      else if (format == FORMAT_MSBLOB)
                          pkey = b2i_PrivateKey_bio(key);
                      else if (format == FORMAT_PVK)
                          pkey = b2i_PVK_bio(key, (pem_password_cb *)password_callback,
                                             &cb_data);
                  #endif
                      else
                      {
                          BIO_printf(err,"bad input format specified for key file
                  ");
                          goto end;
                      }
                  end:
                      if (key != NULL) BIO_free(key);
                      if (pkey == NULL)
                      {
                          BIO_printf(err,"unable to load %s
                  ", key_descrip);
                          ERR_print_errors(err);
                      }
                      return(pkey);
                  }
                  

                  这篇关于如何在没有 p、q 等的情况下加载 RSA 密钥对的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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 中将列表元素移动到末尾)
                  <tfoot id='Wvy1n'></tfoot>
                  • <i id='Wvy1n'><tr id='Wvy1n'><dt id='Wvy1n'><q id='Wvy1n'><span id='Wvy1n'><b id='Wvy1n'><form id='Wvy1n'><ins id='Wvy1n'></ins><ul id='Wvy1n'></ul><sub id='Wvy1n'></sub></form><legend id='Wvy1n'></legend><bdo id='Wvy1n'><pre id='Wvy1n'><center id='Wvy1n'></center></pre></bdo></b><th id='Wvy1n'></th></span></q></dt></tr></i><div id='Wvy1n'><tfoot id='Wvy1n'></tfoot><dl id='Wvy1n'><fieldset id='Wvy1n'></fieldset></dl></div>

                    <legend id='Wvy1n'><style id='Wvy1n'><dir id='Wvy1n'><q id='Wvy1n'></q></dir></style></legend>

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

                    • <bdo id='Wvy1n'></bdo><ul id='Wvy1n'></ul>
                          <tbody id='Wvy1n'></tbody>