【问题标题】:Is RSA Encrypt & Decrypt only with Private Key by openssl, correct?RSA Encrypt & Decrypt 是否仅使用 openssl 的私钥,对吗?
【发布时间】:2016-06-01 05:46:10
【问题描述】:

这是我的测试用例。

$ openssl genrsa -out private.pem 2048
$ openssl rsa -in private.pem -outform PEM -pubout -out public.pem  # but I don't use it.

$ touch raw_data.log && echo 123456 >> raw_data.log
$ openssl rsautl -encrypt -in raw_data.log -inkey private.pem > enc.raw_data.log
$ openssl rsautl -decrypt -in enc.raw_data.log -inkey private.pem > dec.raw_data.log

$ cat raw_data.log
$ cat dec.raw_data.log

为什么我只能使用 rsa 私钥加密和解密数据。(不是加密数据的公钥)

对吗?

【问题讨论】:

    标签: encryption openssl rsa


    【解决方案1】:

    如果您阅读man page for openssl rsautl,您会发现可以使用pubin选项使用公钥进行加密

    -inkey file 输入密钥文件,默认为RSA私钥。

    -pubin 输入文件是一个 RSA 公钥。

    因此您可以使用私钥(默认)或公钥(使用 pubin 选项)进行加密

    openssl rsautl -encrypt -inkey pubkey.pem -pubin -in raw_data.log -out enc.raw_data.log
    

    【讨论】:

      猜你喜欢
      • 2018-10-07
      • 2011-08-21
      • 2012-06-15
      • 2014-05-16
      • 2016-04-07
      • 2016-05-18
      • 2020-02-28
      • 2022-12-02
      相关资源
      最近更新 更多