How to generate DER / PEM certificate from public metric and RSA module?

As you know, a public key consists of an open exponent and a module.

My questions:

How to generate DER / PEM certificate from public metric and RSA module?

Thank you in advance.

+4
source share
1 answer

With a public metric and module, the best you could hope to do is get something like this:

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

However, typically DER / PEM files are used to store private keys, and you won’t be able to get a private exponent when all you have is public. If, however, what you are looking for, let me know and I can post additional instructions on how to get it from the module / public exhibitor!

edit: Here is how I would 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 am using phpseclib, a pure PHP RSA implementation .

+5
source

Source: https://habr.com/ru/post/973240/


All Articles