3

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(public key) を取得する方法はありますか?

4

1 に答える 1

9

純粋な PHP RSA 実装である 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();
于 2013-06-10T18:51:58.713 に答える