开发者

How to generate a DER/PEM certificate from public exponent and modulus of RSA?

开发者 https://www.devze.com 2023-03-05 19:40 出处:网络
As we know, a public key consists of开发者_StackOverflow a public exponent and a modulus. My questions is:

As we know, a public key consists of开发者_StackOverflow a public exponent and a modulus.

My questions is:

How to generate a DER/PEM certificate from public exponent and modulus of RSA?

Thank you very much in advance.


With a public exponent and modulus the best you could hope to do is to get something like this:

-----BEGIN PUBLIC KEY-----
MIGGAoGAfHlcdrcuOK6C02rbGR3SgV/ZJ2wnTiFBguh5FHduoB6LcZz49LIC/KcIiH/TckK8GxQd
oJ7wHCPBpNiumrlC6caj/C8jO/HZ3cb12Wuk4gUuJq1lg5+HTv4KRJ9pFeEFQqS6X+BTztY+EoRx
uc8MlLXS4PUeouwd9Ios2K0Y5/sCASU=
-----END PUBLIC KEY-----

That said, usually DER/PEM files are used to hold private keys and you're not going to be able to get the private exponent when all you have is the public one. If, however, the above is what you're looking for, let me know and I can post further instructions on how to get it from the modulus / public exponent!

edit: Here's how I'd do it:

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

$modulus = new Math_BigInteger($modulusBinaryString, 256);
$exponent = new Math_BigInteger($exponentBinaryString, 256);

$rsa = new Crypt_RSA();
$rsa->modulus = $modulus;
$rsa->exponent = $exponent;
$rsa->publicExponent = $exponent;
$rsa->k = strlen($rsa->modulus->toBytes());

echo $rsa->getPublicKey(CRYPT_RSA_PRIVATE_FORMAT_PKCS1);
?>

I'm using phpseclib, a pure PHP RSA implementation.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号