Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 826877
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T03:29:04+00:00 2026-05-15T03:29:04+00:00

Maybe someone can clear me up. I have been surfing on this a while

  • 0

Maybe someone can clear me up. I have been surfing on this a while now.

Step #1: Create a root certificate

Key generation on unix

1) openssl req -x509 -nodes -days 3650 -newkey rsa:1024 -keyout privatekey.pem -out mycert.pem

2) openssl rsa -in privatekey.pem -pubout -out publickey.pem

3) openssl pkcs12 -export -out mycertprivatekey.pfx -in mycert.pem -inkey privatekey.pem -name "my certificate"

Step #2: Does root certificate work on php: YES

PHP side

I used the publickey.pem to read it into php:

$publicKey = "file://C:/publickey.pem";
$privateKey = "file://C:/privatekey.pem";
$plaintext = "123";

openssl_public_encrypt($plaintext, $encrypted, $publicKey);
$transfer = base64_encode($encrypted);
openssl_private_decrypt($encrypted, $decrypted, $privateKey);

echo $decrypted;  // "123"

OR

$server_public_key = openssl_pkey_get_public(file_get_contents("C:\publickey.pem"));
// rsa encrypt
openssl_public_encrypt("123", $encrypted, $server_public_key);

//and the privatekey.pem to check if it works:
openssl_private_decrypt($encrypted, $decrypted, openssl_get_privatekey(file_get_contents("C:\privatekey.pem")));

echo $decrypted;  // "123"

Coming to the conclusion, that encryption/decryption works fine on the php side with these openssl root certificate files.


Step #3: Does root certificate work on .NET: YES

C# side

In same manner I read the keys into a .net C# console program:

X509Certificate2 myCert2 = null;
RSACryptoServiceProvider rsa = null;

try
{
    myCert2 = new X509Certificate2(@"C:\mycertprivatekey.pfx", "password");
    rsa = (RSACryptoServiceProvider)myCert2.PrivateKey;
}
catch (Exception e)
{
    Console.writeln(e.message); // because I left a blank catch block, I did not realize there was an exception! I missed the password for the certificate.
}

byte[] test = {Convert.ToByte("123")};

string t = Convert.ToString(rsa.Decrypt(rsa.Encrypt(test, false), false));

Coming to the point, that encryption/decryption works fine on the c# side with these openssl root certificate files.


Step #4: Enrypt in php and Decrypt in .NET: YES

PHP side

$onett = "123"
....
openssl_public_encrypt($onett, $encrypted, $server_public_key);
$onettbase64 = base64_encode($encrypted);

copy – paste $onettbase64 (“LkU2GOCy4lqwY4vtPI1JcsxgDgS2t05E6kYghuXjrQe7hSsYXETGdlhzEBlp+qhxzTXV3pw+AS5bEg9CPxqHus8fXHOnXYqsd2HL20QSaz+FjZee6Kvva0cGhWkFdWL+ANDSOWRWo/OMhm7JVqU3P/44c3dLA1eu2UsoDI26OMw=”) into c# program:

C# side

byte[] transfered_onett = rsa.Decrypt(Convert.FromBase64String("LkU2GOCy4lqwY4vtPI1JcsxgDgS2t05E6kYghuXjrQe7hSsYXETGdlhzEBlp+qhxzTXV3pw+AS5bEg9CPxqHus8fXHOnXYqsd2HL20QSaz+FjZee6Kvva0cGhWkFdWL+ANDSOWRWo/OMhm7JVqU3P/44c3dLA1eu2UsoDI26OMw="), false);

string result = System.Text.Encoding.UTF8.GetString(transfered_onett); // "123"

No problems.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T03:29:05+00:00Added an answer on May 15, 2026 at 3:29 am

    You need to use one of the X509Certificate2 constructors that are designed for PFX (aka pkcs#12) files. These take a password argument. In your original example, you were silently swallowing all exceptions so you missed the error.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm betting that someone has already solved this and maybe I'm using the wrong
Possible Duplicate: How do I calculate someone's age in C#? Maybe this could be
Two questions. 1) I understand this must be an expected outcome but maybe someone
Maybe someone found a workaround for the following problem: It seems as if AXIS
Maybe I just don't know .NET well enough yet, but I have yet to
Maybe the need to do this is a 'design smell' but thinking about another
Maybe this is a dumb question, but is there any way to convert a
Maybe I'm just thinking about this too hard, but I'm having a problem figuring
Maybe this applied to other Delphi's (I've only used 7). We've got our code
Maybe this is an overarching question as I've seen similar bugs in Firefox and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.