How to convert RSAParameters from .net to .pem file so that I can use it in php

Hi, I have private and public keys for RSA generated in .net

in this format

string privateKey = "<RSAKeyValue>" +
                         "<Modulus>...kCFhsjB4xMW49mrx5B/Ga...</Modulus>" +
                         "<Exponent>...</Exponent>" +
                         "<P>...7bRCrQVgVIfXdTIH3iY8x...</P>" +
                         "<Q>...4SiQDhrAZADuFDTr7bRCrQVgVIfXdTIH3iY8x...</Q>" +
                         "<DP>...ZADuFDTr7bRCrQVgVIfXdT...</DP>" +
                         "<DQ>...4SiQDhrAZADuFDTr...</DQ>" +
                         "<InverseQ>...sjB4xMW49mrx5B/Ga...</InverseQ>" +
                         "<D>...SiQDhrAZADuFDTr7bRCrQVgVIf...</D>" +
                     "</RSAKeyValue>";

how can i convert this so i can use it in php openssl to encrypt and decrypt data? I need to convert both public and private keys.

maybe with the openssl bash command in linux, where can I specify my own module, exponent and so on?

any ideas?

thank

+3
source share
1 answer

Unfortunately, I did not find a solution for the specific problem that you described, however there are a few workarounds that may come in handy:

  • .NET, PEM. ( , , , , BouncyCastle.
  • , perl.

    Crypt:: OpenSSL:: RSA,
    Crypt:: OpenSSL:: Bignum,
    MIME:: Base64;
    $ modulus = Crypt:: OpenSSL:: Bignum- > new_from_bin (decode_base64 ($ XMLModulus));
    $ exponent = Crypt:: OpenSSL:: Bignum- > new_from_bin (decode_base64 ($ XMLExponent)),
    # , , # dq, dp inverseQ
    $ privateKey = Crypt:: OpenSSL:: RSA → ($ modulus, $exponent, $d, $p, $q)
    # (DER), PHP. print $privateKey- > get_private_key_string()
    # PEM, openssl .

, PHP. , # .

+1

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


All Articles