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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T17:27:16+00:00 2026-05-15T17:27:16+00:00

I have two AsymmetricAlgorithm objects that contain an RSA Private and RSA Public key.

  • 0

I have two AsymmetricAlgorithm objects that contain an RSA Private and RSA Public key. The private key was retrieved out of the Windows-MY keystore and the Public key from a user’s certificate. How can I use these keys along with RSACryptoServiceProvider to encrypt data using the RSA algorithm in C#? In other words, how can I specify that I want to use keys that I already have?

  • 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-15T17:27:16+00:00Added an answer on May 15, 2026 at 5:27 pm
    #region "RSA Encrypt/Decrypt"  
    public string RSAEncrypt(string str, string publicKey)  
    {  
      //---Creates a new instance of RSACryptoServiceProvider---  
      try {  
         RSACryptoServiceProvider RSA = new RSACryptoServiceProvider();  
         //---Loads the public key---  
         RSA.FromXmlString(publicKey);  
         byte[] EncryptedStr = null;  
    
         //---Encrypts the string---  
         EncryptedStr = RSA.Encrypt(ASCII.GetBytes(str), false);  
         //---Converts the encrypted byte array to string---  
         int i = 0;  
         System.Text.StringBuilder s = new System.Text.StringBuilder();  
         for (i = 0; i <= EncryptedStr.Length - 1; i++) {  
             //Console.WriteLine(EncryptedStr(i))  
             if (i != EncryptedStr.Length - 1) {  
                 s.Append(EncryptedStr[i] + " ");  
             } else {  
                 s.Append(EncryptedStr[i]);  
             }  
         }  
    
         return s.ToString();  
       } catch (Exception err) {  
         Interaction.MsgBox(err.ToString());  
       }  
    }  
    
    public string RSADecrypt(string str, string privateKey)  
    {  
      try {  
         //---Creates a new instance of RSACryptoServiceProvider---  
         RSACryptoServiceProvider RSA = new RSACryptoServiceProvider();  
         //---Loads the private key---  
         RSA.FromXmlString(privateKey);  
    
         //---Decrypts the string---  
         byte[] DecryptedStr = RSA.Decrypt(HexToByteArr(str), false);  
         //---Converts the decrypted byte array to string---  
         System.Text.StringBuilder s = new System.Text.StringBuilder();  
         int i = 0;  
         for (i = 0; i <= DecryptedStr.Length - 1; i++) {  
             //Console.WriteLine(DecryptedStr(i))  
             s.Append(System.Convert.ToChar(DecryptedStr[i]));  
         }  
         //Console.WriteLine(s)  
         return s.ToString();  
      } catch (Exception err) {  
         Interaction.MsgBox(err.ToString());  
      }  
    }  
    #endregion 
    

    The Public Key (arg) should look like this:
    <RSAKeyValue>
    <Modulus>yNi8BvATA77f+/6cU6z[…]9VULgU=</Modulus>
    <Exponent>AQAB</Exponent>
    </RSAKeyValue>

    The Private Key (arg) should look like this:
    <RSAKeyValue>
    <Modulus>yNi8BvATA77f+/6cU6z[…]9VULgU=</Modulus>
    <Exponent>AQAB</Exponent>
    <P>8ZlZPmko3sam9pvD/l[…]ba0MWLjj9dyUMvmTQ6L8m9IQ==</P>
    <Q>1NGHjXyEa9SjUwY[…]v+op2YyyglMeK/Gt5SL0v6xqQZQ==</Q>
    <DP>LpjE/aSKnWzzBt1E[…]i5f63Ak9wVG3ZPnwVDwefNkMAQ==</DP>
    <DQ>qAgb8AGNiJom[…]8x3qaD3wx+UbnM5v3aE5Q==</DQ>
    <InverseQ>fQ4+7r3Nmgvz113L[…]uJqEgCNzw==</InverseQ>
    <D>B4n7JNeGHzHe/nqEK[…]GaOBtuz0QTgE=</D>
    </RSAKeyValue>

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

Sidebar

Ask A Question

Stats

  • Questions 445k
  • Answers 445k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You should post your code for your Delete action method… May 15, 2026 at 7:02 pm
  • Editorial Team
    Editorial Team added an answer Yes, you can write to different positions simultaneously from different… May 15, 2026 at 7:02 pm
  • Editorial Team
    Editorial Team added an answer EXISTS, always COUNT will traverse the table or an index:… May 15, 2026 at 7:02 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.