简体   繁体   English

是否可以从 Rust-openssl 中的密码生成 RSA 密钥对?

[英]Is it possible to generate a RSA key-pair from a password in Rust-openssl?

The client store its private key locally and use to sign messages send to server, the server stores the public key of the user in a database to verify messages from client.客户端将其私钥存储在本地并用于对发送到服务器的消息进行签名,服务器将用户的公钥存储在数据库中以验证来自客户端的消息。

Here's my problem, if the client lose its private key due to some accident(like hard-disk being destroyed), it will never be able to connect to server(unless call the administrator of the server to reset his key).这是我的问题,如果客户端由于某些意外(例如硬盘被损坏)丢失了私钥,它将永远无法连接到服务器(除非致电服务器管理员重置其密钥)。

So I'm thinking, if there's an algorithm to generate a deterministic RSA key-pair from a password(which can be kept in the client's human brain), the problem mentioned above will be eliminated.所以我在想,如果有一种算法可以从密码(可以保存在客户端的人脑中)生成确定性的 RSA 密钥对,那么上面提到的问题将被消除。

Is that possible to implement such algorithm using Rust-openssl?可以使用 Rust-openssl 实现这样的算法吗?

Doing this basically boils down to using the password as input to seed a pseudo-random number generator.这样做基本上归结为使用密码作为输入来播种伪随机数生成器。 The same seed will yield the same pseudo-random numbers.相同的种子将产生相同的伪随机数。 An example of doing that to deterministically generate a prime number (which would be used to eventually generate an RSA key) can be found here .可以在此处找到确定性地生成素数(将用于最终生成 RSA 密钥)的示例。 If this is a single-purpose standalone executable, you could then execute RSA_generate_key_ex , otherwise write an RSA key generator (using the BN functions) and import the key.如果这是一个单一用途的独立可执行文件,那么您可以执行RSA_generate_key_ex ,否则编写一个 RSA 密钥生成器(使用 BN 函数)并导入密钥。

Check out dOpenSSL: https://github.com/bernardoaraujor/dopenssl.rs查看 dOpenSSL: https : //github.com/bernardoaraujor/dopenssl.rs

It consists of a deterministic implementation of some of the OpenSSL functionalities, namely:它由一些 OpenSSL 功能的确定性实现组成,即:

  • Deterministic Big Number Generation确定性大数生成
  • Deterministic Pseudo Random Number Generation确定性伪随机数生成
  • Deterministic RSA Keypair Generation确定性 RSA 密钥对生成

I started this repository as an exercise.我开始这个存储库作为练习。 I am also maintaining https://github.com/bernardoaraujor/dopenssl (fork), which is written in C.我也在维护https://github.com/bernardoaraujor/dopenssl (fork),它是用 C 编写的。

My goal in dopenssl.rs is to use bindgen to autogenerate Rust Wrappers.我在 dopenssl.rs 中的目标是使用bindgen自动生成 Rust Wrappers。 dOpenSSL functionality is stable, but Rust Wrappers are a work-in-progress. dOpenSSL 功能稳定,但 Rust Wrappers 仍在开发中。

Contributions are welcome.欢迎投稿。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM