如何根据RSA的公共指数和模数生成DER / PEM证书? [英] How to generate a DER/PEM certificate from public exponent and modulus of RSA?

查看:420
本文介绍了如何根据RSA的公共指数和模数生成DER / PEM证书?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们知道,公共密钥由公共指数和模数组成。

As we know, a public key consists of a public exponent and a modulus.

我的问题是:

如何根据RSA的公共指数和模数生成DER / PEM证书?

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

非常感谢。

推荐答案

使用公共指数和模数,您所希望做的最好的事情就是得到这样的东西:

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

也就是说,通常DER / PEM文件用于保存私钥,而当您拥有的只是公用密钥时,您将无法获得私钥。但是,如果以上是您要寻找的内容,请告诉我,我可以发布进一步的说明,说明如何从模数/公共指数中获取它!

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!

编辑:这是我的做法:

<?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);
?>

我正在使用 phpseclib,纯PHP RSA实现

这篇关于如何根据RSA的公共指数和模数生成DER / PEM证书?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆