简体   繁体   English

使用OpenSSL生成RSA公钥/私钥?

[英]Generate RSA public/private key with OpenSSL?

The main problem is that I'm quite new to C, and the OpenSSL documentation is not clear enough for me, I've tried using Reading and writing rsa keys to a pem file in C , but I don't quite understand it. 主要的问题是我对C很新,而OpenSSL文档对我来说还不够清楚,我已经尝试过将读取和写入rsa键写入C中的pem文件 ,但我不太明白。 For example, how does the create_rsa_key() function creates both the private and the public? 例如, create_rsa_key()函数如何创建私有和公共? And where does pCipher come from? pCipher来自哪里? And what's the point of the pcszPassphrase ? 那个pcszPassphrase什么pcszPassphrase呢?

I'll explain as if it was some sort of pseudocode, this is what I want to do, and the parts in bold are those I don't know how to do it: 我会解释好像它是某种伪代码,这就是我想做的事情,粗体部分是那些我不知道怎么做的部分:

  • generate private key and public key as buffers in hex (client) 生成私钥和公钥作为十六进制缓冲区(客户端)
  • send the public key to the other endpoint safely (client) 将公钥安全地发送到另一个端点(客户端)
  • encrypt some data with a random 256 bit password using AES256 CBC (server) 使用AES256 CBC(服务器)使用随机256位密码加密某些数据
  • encrypt the password using the public key (server) 使用公钥加密密码(服务器)
  • send the encrypted data to the client (server) 将加密数据发送到客户端(服务器)
  • decrypt the encrypted 256 bit password using the private key (client) 使用私钥(客户端)解密加密的256位密码
  • decrypt the file 解密文件

Basically I know how to handle AES encryption/decryption and the communication protocol, they're already implemented anyway, my issue is RSA, and I need hex format not base64 or pem as I'm working with sockets and sending and storing as binary data. 基本上我知道如何处理AES加密/解密和通信协议,它们已经实现了,我的问题是RSA,我需要十六进制格式而不是base64或pem,因为我正在使用套接字并发送和存储为二进制数据。

As discussed on IRC, the answer to the create_rsa_key question is addressed by https://stackoverflow.com/a/29589818/37923 - it's not meant to work that way. 正如在IRC上所讨论的那样,create_rsa_key问题的答案由https://stackoverflow.com/a/29589818/37923解决 - 它并不意味着以这种方式工作。

pcszPassphrase is meant to be the password/phrase to protect the private key. pcszPassphrase是保护私钥的密码/短语。 It would be provided by the user, but isn't a requirement. 它将由用户提供,但不是必需的。

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

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