openssl: how can i get public key from modulus

前端 未结 1 798
感情败类
感情败类 2021-01-14 09:30

I generate a pair of keys using openssl:

shell> ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/mike         


        
相关标签:
1条回答
  • 2021-01-14 10:22

    You can get the public key in a more standardized format using phpseclib, a pure PHP RSA implementation. 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();
    
    0 讨论(0)
提交回复
热议问题