簡體   English   中英

openssl:我如何從模數中獲取公鑰

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

我使用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.

然后,我從私鑰生成模數:

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

現在,有沒有辦法僅從模數中獲取test_rsa.pub(公鑰)?

您可以使用純PHP PHP實現的phpseclib以更標准化的格式獲取公鑰。 例如。

<?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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM