RSA - 你能从私钥创建公钥吗?

发布于 2024-11-15 05:54:51 字数 101 浏览 0 评论 0原文

我正在为一个实验室项目创建加密策略,并想知道是否有能力仅从私钥创建公钥?

否则,公钥只能与某个密钥生成器的私钥同时创建吗?

PS 快速谷歌并没有真正帮助。

I am creating an encryption strategy for a lab project and want to know if there exists the capability to create a public key from just the private key?

Otherwise, can the public key only be created at the same time as the private key from some key generator?

P.S. A quick google didnt really help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

哭了丶谁疼 2024-11-22 05:54:51

私钥和公钥是一起创建的。此外,RSA 私钥的标准存储格式包括所有公钥字段,因为它对于优化实现和屏蔽(防止某些旁路攻击)很有用。请参阅 RSA 标准本身:PKCS#1

编辑:问题已被编辑,它最初仅适用于 RSA。对于其他非对称算法,不要求公钥可以从私钥导出,也不要求相反。对于基于离散对数的算法(Diffie-Hellman、El-Gamal、DSA 以及所有这些算法的椭圆曲线变体),可以轻松地根据私钥计算出公钥。可以设想一种简并的 RSA,其中私钥的知识不允许重建公钥,但这不需要存储良好性能所需的一些关键元素(详细而言,存储 RSA 模数因子允许通过中国剩余定理将速度提高 4 倍,因此每个人都存储因子)。从更概念化的角度来看,公钥是公开的,因此假设“每个人”都知道它;实际上,私钥存储格式几乎总是包括存储公钥的规定,或者至少包含足够的数据来重建公钥。

Private and public key are created together. Also, the standard storage format for a RSA private key includes all the public key fields, because it is useful for optimized implementations and masking (protection against some side-channel attacks). See the RSA standard itself: PKCS#1.

Edit: question has been edited, it was originally RSA-only. For other asymmetric algorithm, there is no requirement that the public key may be derived from the private key, nor is there any requirement of the contrary. For discrete logarithm-based algorithms (Diffie-Hellman, El-Gamal, DSA, and the elliptic curve variants of all of these), the public key is easily computed from the private key. It is possible to conceive a degenerate RSA in which knowledge of the private key does not allow reconstruction of the public key, but this requires not storing a few key elements which are needed for good performance (in full details, storing the RSA modulus factors allows for a 4x speed enhancement through the Chinese Remainder Theorem, so everybody stores the factors). On a more conceptual basis, the public key is, well, public, so it is assumed that "everybody" knows it; in practical terms, private key storage format almost always include provisions for storing the public key as well, or at least sufficient data to rebuild the public key.

后来的我们 2024-11-22 05:54:51

是的,您可以这样做(对于某些(可能不是全部)pkc 方案)。从 ssh-keygen man 文件中:

-y 读取私钥文件并打印公钥。

Yes, you can do this (for some, probably not all, pkc schemes). From the ssh-keygen man file:

-y Read private key file and print public key.

﹏雨一样淡蓝的深情 2024-11-22 05:54:51

取决于算法。使用 RSA 不能,使用 EC 可以。但是,公钥通常总是与私钥存储在一起(当然,不是相反),所以这并不是真正的问题(如果您有私钥,同一文件还包含公钥)。

Depends on the algorithm. With RSA, you cannot, with EC you can. However, the public key is usually always stored together with the private key (not the other way around, though, of course), so this is not really a problem (if you have the private key, the same file also includes the public key).

倾听心声的旋律 2024-11-22 05:54:51

从命令行从私钥中提取 RSA 公钥

命令行比较显示,如果忽略空格,则 RSA 公钥和提取的密钥之间没有区别。

  1. 在主目录下生成公钥私钥配对,无密码且无注释。

    ssh-keygen -t rsa -f ~/id_rsa -N '' -C ""

  2. 将公钥生成到文件“extracted_public_key”

    ssh-keygen -y -f '/home/vagrant/id_rsa' >提取的公共密钥

  3. 将公钥与“extracted_public_key”文件进行比较,忽略空格。

    diff -b id_rsa.pub extract_public_key

忽略 id_rsa.pub 末尾的空格,公钥和提取的密钥之间没有区别。

Extracting public RSA key from a private key from the command line

Command line comparison to show there is no difference between a public RSA key and an extracted key if you ignore whitespace.

  1. Generate public private key pairing under home directory with no passphrase and no coment.

    ssh-keygen -t rsa -f ~/id_rsa -N '' -C ""

  2. Generate public key into file 'extracted_public_key'

    ssh-keygen -y -f '/home/vagrant/id_rsa' > extracted_public_key

  3. Diff public key with 'extracted_public_key' file ignoring white space.

    diff -b id_rsa.pub extracted_public_key

Ignoring whitespace at the end of id_rsa.pub there is no difference between a public key and an extracted key.

宁愿没拥抱 2024-11-22 05:54:51

实际上公钥大多是和私钥一起生成的。

如果您丢失了公钥但获得了私钥,您仍然可以从私钥恢复公钥。

您所要做的就是从私钥中提取公钥,如下所示:

从私钥中提取公钥:

ssh-keygen -f ~/.ssh/test_rsa -y > ~/.ssh/test_rsa.pub

-f 选项指定列出指纹的密钥文件
-y 选项将读取 SSH 私钥文件并将 SSH 公钥打印到标准输出。公钥部分被重定向到与私钥同名但具有 .pub 文件扩展名的文件。

注意:
如果密钥设置了密码,则需要该密码才能生成公钥。

Actually the public key is mostly generated with the private key together.

If you lost your public key but got the private key, you can still recover the public key from the private key.

All you have to do is to extract the public key from the private key like below:

Extracting the public key from the private key:

ssh-keygen -f ~/.ssh/test_rsa -y > ~/.ssh/test_rsa.pub

-f option specifies the file of the key to list the fingerprint for
-y option will read a private SSH key file and prints an SSH public key to stdout. The public key part is redirected to the file with the same name as the private key but with the .pub file extension.

NOTE:
If the key has a password set, the password will be required to generate the public key.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文