简体   繁体   English

openssl:我如何从模数中获取公钥

[英]openssl: how can i get public key from modulus

I generate a pair of keys using openssl: 我使用openssl生成一对密钥:

shell> ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/mike/.ssh/id_rsa): /path/to/test_rsa
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /path/to/test_rsa.
Your public key has been saved in /path/to/test_rsa.pub.

And then, I generate modulus from private key: 然后,我从私钥生成模数:

shell> openssl rsa -in /path/to/test_rsa -noout -modulus > /path/to/modulus.txt

Now, is there any way to get test_rsa.pub(public key) just from modulus? 现在,有没有办法仅从模数中获取test_rsa.pub(公钥)?

You can get the public key in a more standardized format using phpseclib, a pure PHP RSA implementation . 您可以使用纯PHP PHP实现的phpseclib以更标准化的格式获取公钥。 eg. 例如。

<?php
include('Crypt/RSA.php');

$modulus = 'yEQs2LxSHBZgZCH0rRQQy9kmry8g2tNhQL1B9f5azNz9Ce9pXPgSRjVUo1B9Ggb/FK3jy41wWd2IfS6rse3vBzRsabMj29CVODM/19yZPmwEmjJHCgYd+AA2qweKZanDp4FLsSw/kyV5WoPN16GHEMLmLGkJFNIWtzzH5jV+S80=';
$exponent = 'AQAB';

$rsa = new Crypt_RSA();

$modulus = new Math_BigInteger(base64_decode($modulus), 256);
$exponent = new Math_BigInteger(base64_decode($exponent), 256);

$rsa->loadKey(array('n' => $modulus, 'e' => $exponent));
$rsa->setPublicKey();

echo $rsa->getPublicKey();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从PHP OpenSSL库中的现有RSA公钥获取模量和指数 - How to acquire Modulus and Exponent from existing RSA Public Key in PHP OpenSSL Library 如何从公钥中找出模数和指数? - How to find the modulus and exponent from a public key? 如何在PHP中将DSA公钥从OpenSSL转换为OpenSSH格式? - How can I convert DSA public key from OpenSSL to OpenSSH format in PHP? 如何从PHP中的指数,模数和私有指数获取私钥? - how to get private key from exponent , modulus and private exponent in PHP? 使用openssl库在php中构建具有现有模数和指数的公钥PEM文件 - build public key PEM file with existing modulus and exponent in php with openssl library openssl 公钥中从苹果转换公钥 - Transform public key from apple in openssl public key 如何根据RSA的公共指数和模数生成DER / PEM证书? - How to generate a DER/PEM certificate from public exponent and modulus of RSA? 如何使用 openssl 和 rsa 将此 python 加密函数(aes,rsa 公钥)传输到 php? - how do I transfer this python encrypt functions (aes, rsa public key) to php with openssl and rsa? openssl_pkey_get_public返回false,但是密钥确实存在 - openssl_pkey_get_public returning false, but key does exist 使用PHP openssl函数获取公钥长度 - Using PHP openssl functions to get public key length
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM