我不太明白这个问题:
根据https://www.madboa.com/geek/openssl/#key-rsa,您可以从私钥生成公钥。
openssl genrsa -out mykey.pem 1024
openssl rsa -in mykey.pem -pubout > mykey.pub
我最初的想法是它们是成对产生的。
RSA私钥中是否包含该和?还是公钥?
我不太明白这个问题:
根据https://www.madboa.com/geek/openssl/#key-rsa,您可以从私钥生成公钥。
openssl genrsa -out mykey.pem 1024
openssl rsa -in mykey.pem -pubout > mykey.pub
我最初的想法是它们是成对产生的。
RSA私钥中是否包含该和?还是公钥?
当前回答
使用以下命令:
openssl req -x509 -nodes -days 365 -sha256 -newkey rsa:2048 -keyout mycert.pem -out mycert.pem Loading 'screen' into random state - done Generating a 2048 bit RSA private key .............+++ ..................................................................................................................................................................+++ writing new private key to 'mycert.pem' ----- You are about to be asked to enter information that will be incorporated into your certificate request. What you are about to enter is what is called a Distinguished Name or a DN. There are quite a few fields but you can leave some blank For some fields there will be a default value, If you enter '.', the field will be left blank. If you check there will be a file created by the name : mycert.pem openssl rsa -in mycert.pem -pubout > mykey.txt writing RSA key If you check the same file location a new public key mykey.txt has been created.
其他回答
寻找SSH公钥的人…
如果您希望提取用于OpenSSH的公钥,则需要以稍微不同的方式获取公钥
$ ssh-keygen -y -f mykey.pem > mykey.pub
此公钥格式与OpenSSH兼容。将公钥追加到remote:~/。Ssh /authorized_keys,就可以开始了
从SSH-KEYGEN文档(1)
Ssh-keygen -y [-f input_keyfile]
-y该选项将读取私有的OpenSSH格式文件,并将OpenSSH公钥打印到stdout。
在这段代码中,我们首先创建的是RSA密钥,它是私有的,但它也有一对公钥,所以要获得实际的公钥,我们只需这样做
openssl rsa -in mykey.pem -pubout > mykey.pub
希望你得到更多的信息检查这个
被称为“私钥”的文件包含的信息比单独的私钥多得多,它包括生成私钥/公钥对所需的所有数据(质数、模数、指数等)。
很容易看到这些信息:
openssl genrsa -out private.pem 1024 #generate private key file
openssl rsa -in private.pem -text #view info in the private key file
openssl rsa -in private.pem -pubout -out public.pem #extract public key to file
openssl rsa -in public.pem -pubin -text #view info in the public key file
您将看到私钥文件包括质数和所有其他信息,而公共文件只包括模数和公共指数。
首先简要回顾一下RSA密钥生成。
随机选择两个大小合适的可能质数(p和q)。 两个质数相乘得到模量(n)。 选择一个公共指数(e)。 用质数和公共指数做一些数学运算,以生成私有指数(d)。
公钥由模数和公共指数组成。
最小私钥由模数和私钥指数组成。从已知的模数和私有指数到相应的公共指数,没有计算上可行的万无一失的方法。
然而:
实用的私钥格式几乎总是存储超过n和d的数据。 E通常不是随机选取的,而是使用少数几个已知值中的一个。如果e是一个众所周知的值,你知道d,那么通过试错很容易求出e。
在大多数实际的RSA实现中,你可以从私钥中获得公钥。建立一个基于RSA的密码系统是可能的,而这是不可能的,但这不是做的事情。
使用以下命令:
openssl req -x509 -nodes -days 365 -sha256 -newkey rsa:2048 -keyout mycert.pem -out mycert.pem Loading 'screen' into random state - done Generating a 2048 bit RSA private key .............+++ ..................................................................................................................................................................+++ writing new private key to 'mycert.pem' ----- You are about to be asked to enter information that will be incorporated into your certificate request. What you are about to enter is what is called a Distinguished Name or a DN. There are quite a few fields but you can leave some blank For some fields there will be a default value, If you enter '.', the field will be left blank. If you check there will be a file created by the name : mycert.pem openssl rsa -in mycert.pem -pubout > mykey.txt writing RSA key If you check the same file location a new public key mykey.txt has been created.