We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Create instance of PKCS1 from X509Certificate2


Can you let me know if it is possible to create an instance of a PKCS1 object from a standard .Net X509Certificate2 type?

Hello Mat,

Thanks for your interest in our products and sorry for replying you late.

We are working over this query and will get back to you soon. We apologize for the delay and inconvenience.

Hi Mat,

As I shared with you earlier that currently Aspose.Pdf for .NET only allows you to sign the PDF file from PFX file. However, if you have some particular scenario regarding X509Certificate2 then please share the details with us, so we would be able to provide support for the feature accordingly.

We’re sorry for the inconvenience.

Hi, thanks for getting back to me.

This is what I am trying to do.

I can digitally sign a document using a pfx file. However I want to place this pfx into the local key store (as most organisations would want to do). So, at run time, I read the key store and attempt to generate the PKCS1 object.

I’ve attached the code I am using to attempt to get this to work, together with a test pfx certificate and a test PDF file.

Hi Mat,

<!–[if gte mso 9]>
<m:mathFont m:val=“Cambria Math”/>
<m:brkBin m:val=“before”/>
<m:brkBinSub m:val="–"/>
<m:smallFrac m:val=“off”/>
<m:lMargin m:val=“0”/>
<m:rMargin m:val=“0”/>
<m:defJc m:val=“centerGroup”/>
<m:wrapIndent m:val=“1440”/>
<m:intLim m:val=“subSup”/>
<m:naryLim m:val=“undOvr”/>
<![endif]–><!–[if gte mso 10]>

/* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-priority:99; mso-style-parent:""; mso-padding-alt:0in 5.4pt 0in 5.4pt; mso-para-margin:0in; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:10.0pt; font-family:"Times New Roman","serif";}


<span style=“font-size:10.0pt;font-family:“Arial”,“sans-serif”;mso-fareast-font-family:
SimSun;mso-fareast-language:ZH-CN”>I am afraid the requested feature is
currently not supported but for the sake of implementation, I have logged this
requirement in our issue tracking system under New Features list as <span style=“font-size:10.0pt;mso-bidi-font-size:12.0pt;font-family:“Arial”,“sans-serif”;
<span style=“font-size:10.0pt;font-family:“Arial”,“sans-serif”;mso-fareast-font-family:
SimSun;mso-fareast-language:ZH-CN”>. We will investigate this issue in details
and will keep you updated on the status of a correction.

Thanks for getting back to me. In the meantime are they any code examples around using the constructor

PKCS1(, )

If I try to use this I’m getting a stream closed error when I attempt to sign a document.

No worries, got it sorted using the following;

PKCS1 res = null;

// Read from file works fine
// res = new PKCS1(@“C:\Users\lonesheep\Documents\tmp\cert\pkcs10.pfx”, “toto”);

// …what I want to do is get the pfx from the local keystore and create the PKCS1 from a stream
X509Store store = new X509Store(StoreName.My, StoreLocation.CurrentUser);
X509Certificate2Collection certCollection =
store.Certificates.Find(X509FindType.FindByTimeValid, DateTime.Now, false);
X509Certificate2Enumerator enumerator = certCollection.GetEnumerator();
X509Certificate2 cert = null;
while (enumerator.MoveNext())
if (enumerator.Current.FriendlyName.CompareTo(“someFriendlyname”) == 0)
cert = enumerator.Current;

byte[] pkcs10 = cert.Export(X509ContentType.Pfx, “toto”);
MemoryStream memStream = new MemoryStream();
BinaryWriter binWriter = new BinaryWriter(memStream);
memStream.Position = 0;
res = new PKCS1(memStream, “toto”);

Hi Mat,

I am pleased to hear that your requirement has been accomplished. In case we can be of any further assistance, please feel free to contact.

The issues you have found earlier (filed as PDFNET-29443) have been fixed in Aspose.PDF for .NET 19.3.