Linux openssl/RSA - 使用公钥解密

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14327517/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 18:40:04  来源:igfitidea点击:

openssl/RSA - Using a Public key to decrypt

linuxopensslrsa

提问by musasabi

I'm looking to secure the software update procedure for a little device I'm maintaining that runs Linux. I want to generate an md5sum of the update package's contents and then encrypt that hash with a private key before sending it out to the customer. When they load the update, the device should then decrypt the hash, verify it, and proceed with installation of the package.

我希望确保我正在维护的运行 Linux 的小设备的软件更新程序安全。我想生成更新包内容的 md5sum,然后在将其发送给客户之前用私钥加密该哈希。当他们加载更新时,设备应该解密哈希,验证它,然后继续安装包。

I'm trying to do this with OpenSSL and RSA. I found thisthread, and was discouraged. I then found thisthread and wondered how Perl gets around the purported impossibility of it all. I'm doing this in C, so perhaps there's a parallel function in an SSL library somewhere?

我正在尝试使用 OpenSSL 和 RSA 来做到这一点。我找到了这个线程,并感到气馁。然后我找到了这个线程,并想知道 Perl 如何解决所有所谓的不可能的问题。我在 C 中做这个,所以也许在某个地方的 SSL 库中有一个并行函数?

So my question really is: can I force command line Linux to take a public key as the decryption input, or perhaps use C to circumvent that limitation?

所以我的问题真的是:我可以强制命令行 Linux 将公钥作为解密输入,还是使用 C 来规避该限制?

Thanks in advance, all.

提前谢谢大家。

采纳答案by larsks

Let's assume you have generated a public and private RSA key using openssl genrsa:

假设您已使用以下方法生成了公共和私有 RSA 密钥openssl genrsa

$ openssl genrsa -out mykey
Generating RSA private key, 512 bit long modulus
...++++++++++++
..........++++++++++++
e is 65537 (0x10001)
$ openssl rsa -in mykey -pubout -out mykey.pub
writing RSA key

You can sign something with the private key like this:

你可以用这样的私钥签名:

$ md5sum myfile | openssl rsautl -inkey mykey -sign > checksum.signed

You can verify this data using the public key:

您可以使用公钥验证此数据:

$ openssl rsautl -inkey mykey.pub -pubin -in checksum.signed
df713741d8e92b15977ccd6e019730a5  myfile

Is this what you're looking for?

这是你要找的吗?