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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:18:36+00:00 2026-05-27T09:18:36+00:00

I encrypt and decrypt data using the RSACryptoServiceProvider in C#, and when I generate

  • 0

I encrypt and decrypt data using the RSACryptoServiceProvider in C#, and when I generate a new keypair, I return the private key to the caller of the method and then save the public key to a homemade PKI (just a dictionary with the keyBlob and a unique identifier).

My problem is this: since I need to store the public key, I don’t want to accidentally store a private key in the PKI. However, since I also need to actually write the private key to a file, I am working with byte arrays exported with the ExportCspBlob method.

My question:
How do I ensure, by checking the byte[] that I parse into my StoreKey method, that it is in fact a public key and it does not contain private key information?

For clarification, here is the relevant code:

public static bool StoreKey(byte[] publicKeyParameters, string uniqueIdentifier)
{
    bool success = false;
    if (!keyCollection.ContainsKey(uniqueIdentifier))
    {
        if (!keyCollection.ContainsValue(publicKeyParameters))
        {
            keyCollection.Add(uniqueIdentifier, publicKeyParameters);
            success = true;
        }
    }
    return success;
}

And the GenerateKeys method:

public static byte[] GenerateKeys(string uniqueIdentifier)
{
    byte[] privateKeyBlob;

    using (var rsa = new RSACryptoServiceProvider(4096))
    {
        try
        {
            byte[] publicKey = rsa.ExportCspBlob(false);

            privateKeyBlob = rsa.ExportCspBlob(true);

            PublicKeyInfrastructure.StoreKey(publicKey, uniqueIdentifier);
        }
        finally
        {
            //// Clear the RSA key container, deleting generated keys.
            rsa.PersistKeyInCsp = false;
        }
    }
    return privateKeyBlob;
}

Since I am working on two different classes, I would like to abstain from initializing a RSACryptoServiceProvider in my PKI, just to import the key and check for it. Is this possible?

  • 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-27T09:18:37+00:00Added an answer on May 27, 2026 at 9:18 am

    According to MSDN, the output of ExportCspBlob is compatible with CAPI, and according to the documentation for the CAPI BLOBHEADER, the first byte represents the key type. Specifically, if the first byte is 0x07, it’s a private key, whereas 0x06 is a public key.

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

Sidebar

Related Questions

I want to encrypt some server data using .NET's RSACryptoServiceProvider and decrypt it when
I'm using C# to generate an RSA public/private key to encrypt user information. I
I'm trying to encrypt and decrypt data using RSA in C#. I have the
I am trying the most basic thing - encrypt data using the public key
I'm using this code snippet to encrypt/decrypt data in my app's database: http://www.androidsnippets.com/encryptdecrypt-strings It
i want to Encrypt and Decrypt data in J2ME using AES Algorithm with bouncy
here are my methods for encrypting and decrypting data using RSA: private RSACryptoServiceProvider _RSACSP
I have a CryptoAPI code to encrypt\ decrypt given data using AES-128 and a
I tried to encrypt data using this function in PHP and decrypt it with
I would like to generate private key in java, save it as a 64

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.