0

I am using ASP.NET, C# and iTextSharp 5.3.0 for creating and digitally signing a PDF. Then I need to use pfx file while signing. Can someone explain what it will contain?

Edit:

Thanks, so it is having the keypair.

I did used this code.

FileStream fs = new FileStream(CERT_PATH, FileMode.Open);
Pkcs12Store ks = new Pkcs12Store(fs, CERT_PASSW.ToCharArray());
string alias = null;
foreach (string al in ks.Aliases) 
{
if (ks.IsKeyEntry(al) && ks.GetKey(al).Key.IsPrivate) 
  {
    alias = al;
    break;
  }
}
  Certificate[] x = ks.getCertificateChain(alias)
  X509Certificate[] chain=new X509Certificate[x.length]
  for(int k=0;k<x.length;k++)
  {
      chain[k]=x[k].Certificate;
  }

Thanks, It is working fine now.

Giri
  • 931
  • 11
  • 31
  • 51
  • 2
    check this stack answer http://stackoverflow.com/a/379033/1358004 – Viral Shah Sep 18 '12 at 05:25
  • can someone tell me how to get upvote for this question? Because i did changed the post but no response. I lost my access for asking question.Then is it possible to recover state from closed. – Giri Dec 19 '12 at 12:06
  • I hope it increases the quality some what. – Giri Dec 24 '12 at 11:45

1 Answers1

2

Please read the white paper on iText and digital signatures: http://itextpdf.com/book/digitalsignatures

A PFX file is an old type of file containing a private and public key pair. You can use it the same way you'd use a P12 file. This is explained in the documentation. Note that old answers on Stackoverflow no longer apply. The digital signature functionality has been completely rewritten.

In case you don't know how to create a KeyStore in C#:

FileStream fs = new FileStream(CERT_PATH, FileMode.Open);
Pkcs12Store ks = new Pkcs12Store(fs, CERT_PASSW.ToCharArray());
string alias = null;
foreach (string al in ks.Aliases) {
    if (ks.IsKeyEntry(al) && ks.GetKey(al).Key.IsPrivate) {
        alias = al;
        break;
    }
}
Bruno Lowagie
  • 75,994
  • 9
  • 109
  • 165
  • thanks..but i m not able to use keystore class for reading.i m using C#. – Giri Sep 18 '12 at 09:56
  • Er... In that case I understand why other people downvoted (and closed) the question (you got an upvote from me). I've added a code sample, but really: you should do a better effort when asking questions. It's bad for your reputation if you don't... – Bruno Lowagie Sep 18 '12 at 10:16