Certificate for Signdigitally?

Can an example be given of how to properly use makecert.exe to create a .cer file for use with Signdigitally I'm using the code from Bob Watson's article:

void SignDocument(string srcXpsDocument, string certFilename)
{
XpsDocument document =
new XpsDocument(srcXpsDocument, FileAccess.ReadWrite);

X509Certificate certificate =
X509Certificate.CreateFromCertFile(certFilename);
document.SignDigitally(certificate, true,
XpsDigSigPartAlteringRestrictions.None);

document.Close();
}

But get various error messages at SignDigitally saying that the certificate is corrupt, or can't be found, although when I mouse over "certificate" I can see that CreateFromCertFile loaded it OK. Perhaps this approach is out of date and a new method of signing exists

Thanks,
Leonard



Answer this question

Certificate for Signdigitally?

  • Rob Reis

    My pleasure.
  • Alexander Gehres

    I was able to successfully sign an XPS document using the "Africa.cer" file produced using your two commands and Bob Watson's code in the first post. Thank you very much!
  • Meryl Junik

    I get serveral different error messages depending on the parameters I supply to makecert. I read the documentation you pointed to but there are many parameters. I am using it on the same machine it was generated on. What I was hoping for was that if someone had used makecert to make a certificate for this purpose, they would post the exact command line they used to make it. Otherwise, if someone has signed an XPS doc with a certificate made using some other tool, if they would post how they made it.

    Thanks,

    Leonard


  • John Rapp

    In using the XPS viewer provided in the Feb CTP it will not allow me to sign a document even though I have a certificate in my personal store. Are there particular requirements of the certificate for this feature of the XPS viewer to work

    Thank you in advance.



  • Andrew Lisogor

    I understand your frustration - I find makecert a little bit obtuse myself. Here's a command I use to generate test certificates:

    makecert.exe -n "CN=Continents, O=World, L=Earth, C=All" -ss "Root" -a sha1 -len 2048 -r -cy authority -sr "LocalMachine"

    makecert.exe -n "CN=Africa" -len 2048 -a sha1 -cy end -is "Root" -in "Continents" -ir "LocalMachine" -ss "My" -sr "CurrentUser" .\Africa.cer

    The first call creates a Certificate Authority called "Continents", and the second call creates a certificate with the name "Africa" that is issued by the first. You should be able to sign using the Africa certificate. Let me know how this works out for you.

    Bruce


  • Tanvir

    Documentation for makecert.exe can be found here:

    http://msdn2.microsoft.com/en-us/library/bfsktky3.aspx

    What exact error are you receiving Are you using the certificate on the same machine that you are generating it on


  • Certificate for Signdigitally?