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 7129453
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T11:14:39+00:00 2026-05-28T11:14:39+00:00

I have AsymmetricKeyParameter object for private and public key. What is the easiest way

  • 0

I have AsymmetricKeyParameter object for private and public key. What is the easiest way to see if they match?

I am trying to encrypt some text (private key) and decrypt some text (public key).
So far I have not been able to do that but it seems like the wrong approach.

Update: Here is sample code:

X509Certificate2 c = new X509Certificate2(@"certificate.cer");
byte[] privateKeyData = System.IO.File.ReadAllBytes(@"private.key");
Org.BouncyCastle.X509.X509Certificate cert = DotNetUtilities.FromX509Certificate(c);


RsaPrivateCrtKeyParameters privateKey = (RsaPrivateCrtKeyParameters)PrivateKeyFactory.CreateKey(privateKeyData);
RsaKeyParameters publicKey = (RsaKeyParameters)cert.GetPublicKey();

if (privateKey.Modulus.Equals(publicKey.Modulus) && publicKey.Exponent.Equals(privateKey.PublicExponent)) 
{
     //they match
}
  • 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-28T11:14:39+00:00Added an answer on May 28, 2026 at 11:14 am

    The simplest way to check whether a private key and a public key match is to encrypt a piece of data with the public key and see if you can decrypt it with the private key – or alternatively to sign a piece of data with the private key and see if you can verify it with the public key.

    If the keys are RSA keys, you can cast the public key to Org.BouncyCastle.Crypto.Parameters.RsaKeyParameters and the private key to Org.BouncyCastle.Crypto.Parameters.RsaPrivateCrtKeyParameters and verify that the Modulus is the same and that Exponent of the public key is equal to PublicExponent of the private key. If you want to get really fancy, you could also validate all the remaining parameters of the private key (follow PKCS#1 section 3.2).

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

Sidebar

Related Questions

have written this little class, which generates a UUID every time an object of
Have a painfully simple blog Post creator, and I'm trying to check if the
have a nice day. I got problem when trying to create an image from
Have following listener for keyboard ArrowDown event(it's key code is 40 ): window.onload =
have been trying couple of hours now to make my iphone app universal. The
Have some code: using (var ctx = new testDataContext()) { var options = new
have some headers like: HTTP/1.1 100 Continue HTTP/1.1 302 Found HTTP/1.1 200 OK HTTP/1.1
Have a question - you see a lot of free font conversion tools online.
Have some dates in my local Oracle 11g database that are in this format:
have the following text file: <div> <asp:HyperLinkField HeaderText=Hello World of Regular Expression /> </div>

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.