微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何将 -pubin 与 openssl来自 libressl一起使用?

如何解决如何将 -pubin 与 openssl来自 libressl一起使用?

https://www.keycdn.com/blog/openssl-tutorial

以上页面中的以下文字对我来说没有意义。

If that file doesn't also include the private key,you must indicate so using -pubin

它前面的文字应该指的是私钥而不是公钥。

The <key.pem> is the file containing the public key. 

以下命令是我想出来的。

openssl genrsa -out key.pem 1024
echo 'Hello World!' > input.txt
openssl pkeyutl -encrypt -in input.txt -inkey key.pem -out output.txt
openssl pkeyutl -decrypt -in output.txt -inkey key.pem -out output_decypt.txt

谁能告诉我一些关于如何使用 -pubin 的工作示例?谢谢。

$ openssl version -a
LibreSSL 3.2.3
built on: date not available
platform: information not available
options:  bn(64,64) rc4(16x,int) des(idx,cisc,16,int) idea(int) blowfish(idx) 
compiler: information not available
OPENSSLDIR: "/usr/local/etc/libressl"

解决方法

Meta:这不是编程问题或问题,尽管过去在 openssl 命令行上有问题,但社区在过去几年中对时事性变得更加严格。两种方式我都没有强烈的感觉,但如果共识是结束,我会删除它。

OpenSSL(及其分支 LibreSSL,从现在开始应该被认为包含在我的所有参考文献中)支持两个“私钥”文件(实际上包含一个密钥 pair -- 私有 公开的,并且必须保持私有)和仅包含公钥的“公钥”文件(因此可以公开)。 pkeyutl(以及旧版 rsautl)同时支持这些和 (X.509v3) 证书文件;证书包含一个公钥,但与公钥不同,格式也不相同。

OpenSSL 支持的私钥文件实际上有多种变体;只要您使用 OpenSSL,它们之间的区别就无关紧要,但是当您想与其他软件接口或互操作时,它们之间的区别就很重要。几乎所有执行 X.509 风格非对称加密的软件都支持证书文件(PEM 和 DER)。 (这不包括 PGP、SSH、Signal 等。)对单独的公钥文件的支持不太常见,虽然很多东西都支持某种类型的私钥文件,但并不总是与 OpenSSL 的一种相同。

所有这三种文件类型都可以是 PEM 格式或“DER”格式。 (从技术上讲,这两种情况下的数据都是 ASN.1-DER 编码的,但“DER”文件只是 DER,而 PEM 文件是 PEM 包装——base64 带有换行符和标题/尾随行—— - 围绕 DER。)私钥文件还可以加密(使用密码)或不加密;公钥和证书文件从不加密。

解密和签名需要私钥,因此仅限于密钥“所有者”。加密和验证只需要公钥,这是一些系统总是使用证书,但OpenSSL有更多的选择。

openssl genrsa 2048 >private.pem 
# writes a private key,by default in PEM,but you can specify -outform DER
# if you add a cipher option like -aes128 or -des3 it is encrypted,else not
# or
openssl genpkey -algorithm RSA -pkeyopt rsa_keygen_bits:2048 >private.pem
# ditto
# PS: 1024-bit RSA,although not actually broken yet,since 2014 
# is not considered to provide adequate safety for most purposes

openssl rsa <private.pem -pubout >public.pem 
# writes a public key file,again by default in PEM
# or
openssl pkey <private.pem -pubout >public.pem 

openssl req -new -x509 -key private.pem -subj "/C=XX/ST=Utopia/O=Chaotic/CN=ReallyME" >cert.pem
# creates a self-signed certificate _containing_ (and signed by) this keypair 
# with specified name,and defaults for other parameters;
# there are lots more options,see the man page or many existing Qs.
# Self-signed cert is mostly useful for test and debug,but not trusted in production; 
# for a real cert you need to apply to a suitable Certificate Authority 
# which is more complicated,and much more variegated,than I can fit here.

openssl pkeyutl -encrypt <data -inkey private.pem >encrypted
openssl pkeyutl -encrypt <data -pubin -inkey public.pem >encrypted
openssl pkeyutl -encrypt <data -certin -inkey cert.pem >encrypted
openssl pkeyutl -decrypt <encrypted -inkey private.pem >decrypted 

openssl sha256 <data -sign private.pem >sig
# this form supports only private key file
openssl sha256 <data -verify public.pem -signature sig
openssl sha256 <data -prverify private.pem -signature sig 
# and this form supports only key files but not cert

openssl sha256 <data -binary | pkeyutl -sign -inkey private.pem -pkeyopt digest:sha256 >sig
openssl sha256 <data -binary | pkeyutl -verify -inkey private.pem -pkeyopt digest:sha256 -sigfile sig 
openssl sha256 <data -binary | pkeyutl -verify -pubin -inkey public.pem -pkeyopt digest:sha256 -sigfile sig 
openssl sha256 <data -binary | pkeyutl -verify -certin -inkey cert.pem -pkeyopt digest:sha256 -sigfile sig 

# end

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?