我不太明白这个问题:
根据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私钥中是否包含该和?还是公钥?
当前回答
寻找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。
其他回答
使用以下命令:
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.
openssl genrsa -out mykey.pem 1024
实际上会产生一个公私钥对。该对存储在生成的mykey中。pem文件。
openssl rsa -in mykey.pem -pubout > mykey.pub
将提取公钥并打印出来。这里有一个页面的链接,可以更好地描述这一点。
编辑:在这里检查示例部分。只输出私钥的公开部分:
openssl rsa -in key.pem -pubout -out pubkey.pem
使用SSH -keygen获取SSH使用的公钥:
ssh-keygen -y -f key.pem > key.pub
寻找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,私钥被表示为PKCS#1 RSAPrivatekey对象或其变体:
A.1.2 RSA private key syntax An RSA private key should be represented with the ASN.1 type RSAPrivateKey: RSAPrivateKey ::= SEQUENCE { version Version, modulus INTEGER, -- n publicExponent INTEGER, -- e privateExponent INTEGER, -- d prime1 INTEGER, -- p prime2 INTEGER, -- q exponent1 INTEGER, -- d mod (p-1) exponent2 INTEGER, -- d mod (q-1) coefficient INTEGER, -- (inverse of q) mod p otherPrimeInfos OtherPrimeInfos OPTIONAL }
正如您所看到的,这种格式有许多字段,包括模数和公共指数,因此是RSA公钥信息的严格超集。
首先简要回顾一下RSA密钥生成。
随机选择两个大小合适的可能质数(p和q)。 两个质数相乘得到模量(n)。 选择一个公共指数(e)。 用质数和公共指数做一些数学运算,以生成私有指数(d)。
公钥由模数和公共指数组成。
最小私钥由模数和私钥指数组成。从已知的模数和私有指数到相应的公共指数,没有计算上可行的万无一失的方法。
然而:
实用的私钥格式几乎总是存储超过n和d的数据。 E通常不是随机选取的,而是使用少数几个已知值中的一个。如果e是一个众所周知的值,你知道d,那么通过试错很容易求出e。
在大多数实际的RSA实现中,你可以从私钥中获得公钥。建立一个基于RSA的密码系统是可能的,而这是不可能的,但这不是做的事情。