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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T15:21:22+00:00 2026-05-21T15:21:22+00:00

I need, in C# (4.0), to sign an XML (XMLDSig Envelope) using a X509Certificate

  • 0

I need, in C# (4.0), to sign an XML (XMLDSig Envelope) using a X509Certificate (a .p7b file provided by the one which should verify the signature)
I do not have experience in security, my knowledge stops to some basic concepts about cryptography .

Here is what i have done:

1) I have installed the certificate in: Certificates – Current User – Trusted Root Certification.

2) from .net i succesfully loaded the certificate with this code:

X509Store store = new X509Store(StoreName.Root, StoreLocation.CurrentUser);
try
{
    store.Open(OpenFlags.ReadOnly);
    X509Certificate2Collection certs = store.Certificates.Find(X509FindType.FindBySubjectName, certName, false);
    if (certs.Count == 0)
        return null;

    return certs[0];
}
finally
{
    store.Close();
}

3) I tried to use the public key of the certificate to create a signature with the following code;

XmlDocument doc = new XmlDocument();
doc.PreserveWhitespace = true;
var reader = new StringReader(xml);
doc.Load(reader);
var signedXml = new SignedXml(doc);
X509Certificate2 certificate = this.GetCertificateFromStore(certName); // the previous code
signedXml.SigningKey = (RSACryptoServiceProvider)certificate.PublicKey.Key;
var reference = new Reference();
reference.Uri = "";
XmlDsigEnvelopedSignatureTransform env = new XmlDsigEnvelopedSignatureTransform();
reference.AddTransform(env);
signedXml.AddReference(reference);
signedXml.ComputeSignature(); //  exception!!!
var element = signedXml.GetXml();
doc.AppendChild(doc.ImportNode(element, true));

but when computing the signature i get an exception: “Object contains only the public half of a key pair. A private key must also be provided.”

I checked the property HasPrivateKey in the certificate and it is false.
My (basic) understanding is that I should not have the private key and I should be able to create a signature using the public key.

What I’m missing ?

Thanks in advance

  • 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-21T15:21:23+00:00Added an answer on May 21, 2026 at 3:21 pm

    .p7b stands for PKCS#7 format which doesn’t normally contain a private key. When you sign the document, you prove it’s authenticity by applying a private key, which belongs to you and which you must keep secret. So it’s very unlikely that anyone (besides probably your network administrator or sometimes a bank) would give you your private key.

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

Sidebar

Related Questions

I need to sign a pdf file with my own e-signature using a certificate
I'm using an XML POST to sign in my users and I need to
i am making android UI (using Relative Layout)in which, i need to set one
I need to sign and verify a string using my company's digital certificate. The
Trying to use GnuPG with Delphi (Win32). I need to sign some file with
I am aware of the Amazon.com exposed URIs ... which I need to sign
I need to sign my soap request to a 3rd party. The provided an
I´m trying to sign some text or XML node using my certificates, installed on
I'm writing a Haskell program which generates an XML file. Apparently it is considered
I need to sign Android application ( .apk ). I have .pfx file. I

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.