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

As we know, a public key consists of 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:

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

?>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值