1

I have two binary buffers containing the modulus and exponent of a public RSA key in PHP (both in big-endian). I need to convert these two values to a PEM formatted string so that it can be used to encrypt data with the openssl extension, for example with openssl_public_encrypt.

When researching this topic, I only found solutions using phpseclib, which I cannot use in this scenario. How can I convert the values manually (as I think openssl doesn't offer such functionality)?

Louis Bernard
  • 229
  • 4
  • 20
  • Is it only phpseclib that you can't use or does it also apply to other third party libraries? – Topaco May 05 '23 at 17:05
  • The prefered way is without using third party libraries at all. – Louis Bernard May 05 '23 at 17:58
  • 1
    Then you have to generate a PEM key from modulus and exponent with appropriate effort. Here is a possible [starting point](https://stackoverflow.com/q/61032127/9014097). The post contains a corresponding function `createPemFromModulusAndExponent()` (but beware the function has a minor bug and needs to be fixed as described in the answer/comments). – Topaco May 05 '23 at 18:11

0 Answers0