Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Thu Sep 07, 2017 4:47 am

i want to ask how do i build digital id/digital signature.
i have follow this guidance https://www.e-iceblue.com/Tutorials/Spire.PDF/Demos/Security/PDF-DigitalCertificate-C-VB.NET.html but i get an error.

the first error is
1err.PNG
, though i have put a txt in the application folder.
but anyway i comment that section. the main problem is when try to make a certificate it pop up error
3rr.PNG


the main code is
Code: Select all
 Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim doc As New PdfNewDocument()

        ' Create one page
        Dim page As PdfPageBase = doc.Pages.Add()

        'Draw the page
        DrawPage(page)

        Dim pfxPath As String = Application.StartupPath + "\Demo.pfx"
        Dim cert As New PdfCertificate(pfxPath, "12345")

        Dim signature As New PdfSignature(doc, page, cert, "demo")
        signature.ContactInfo = "Haaaaa"
        signature.Certificated = True
        signature.DocumentPermissions = PdfCertificationFlags.AllowFormFill

        'Save pdf file.
        doc.Save("DigitalSignature.pdf")
        doc.Close()

        'Launching the Pdf file.
        Process.Start("DigitalSignature.pdf")
    End Sub


note: my main form load layout only got button

blueeyeswhite
 
Posts: 15
Joined: Mon Jun 19, 2017 9:03 am

Thu Sep 07, 2017 6:44 am

Dear blueeyeswhite,

Thanks for your inquiry.
I have checked the code. For the first error, I found the code result.Remainder returns null as there is no text which is not layouted. Please replace it with the string.
As for the second issue, the code could work on my side. Please make sure the path which includes file name is correct on your side. If there is any question, please let me know.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Thu Sep 07, 2017 8:06 am

thanks for your reply.

before you replied what i have tried is
for issue no. 1, i have tried by replace it by string. and it don't give me an error and it work like u said.
and for issue no.2 i got it worked by copy the demo.pfx to my application (bin) and it work. And what i though before , that this code is make a new certficate but instead its just reading the certificate that exist. CMIIW

Code: Select all
 Dim pfxPath As String = Application.StartupPath + "\Demo.pfx"
          Dim cert As New PdfCertificate(pfxPath, "e-iceblue")


now the question is how do i really a new certificate, so i can read my certificate that i made with the code above ?
i can't find it on the demo. the demo just using the same code as above
thanks

blueeyeswhite
 
Posts: 15
Joined: Mon Jun 19, 2017 9:03 am

Thu Sep 07, 2017 8:24 am

Dear blueeyeswhite,

Thanks for your prompt response.
Sorry that now Spire.PDF only supports loading an existing certificate, and the PdfCertificate cannot create a new certificate.
In addition, I found there is useful information which might help you.
If I misunderstanding, please let me know.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Fri Sep 08, 2017 9:05 am

thanks for your referral.
unfortunately it's kinda hard for me to understand and implement it
is there any near future developing this feature ?

blueeyeswhite
 
Posts: 15
Joined: Mon Jun 19, 2017 9:03 am

Fri Sep 08, 2017 10:13 am

Dear blueeyeswhite,

Sorry that we don't have that plan to develop the feature.
After further investigation, I found there is a simple way to create a certificate. Sample code for your reference.
Code: Select all
            //create certificate
            X509Store storex = new X509Store(StoreName.My, StoreLocation.CurrentUser);
            storex.Open(OpenFlags.ReadOnly);
            X509Certificate2 certificatex = storex.Certificates[0];
            storex.Close();
            byte[] bytecertificate = certificatex.Export(X509ContentType.Cert,"abc123");
            PdfCertificate cert = new PdfCertificate(bytecertificate, "abc123");
            //sign PDF
            PdfNewDocument doc = new PdfNewDocument();
            PdfPageBase page = doc.Pages.Add();
            PdfSignature signature = new PdfSignature(doc, page, cert, "demo");
            signature.ContactInfo = "Haaaaa";
            signature.Certificated = true;
            signature.DocumentPermissions = PdfCertificationFlags.AllowFormFill;
            doc.Save("Create11541.pdf");

Hope this helps. If there is any question, welcome to get it back to us.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Mon Sep 11, 2017 8:37 am

thanks your reply. i have tried using your code.
but iam using vb, when i try to translate it. it gives me an error
Code: Select all
 
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

        Dim storex As X509Store = New X509Store(StoreName.My, StoreLocation.CurrentUser)
        storex.Open(OpenFlags.ReadOnly)
        Dim certificatex As X509Certificate2 = storex.Certificates(0)
        storex.Close()
        Dim bytecertificate As Byte() = certificatex.Export(X509ContentType.Cert, "abc123")

        Dim doc As New PdfNewDocument()

        ' Create one page
        Dim page As PdfPageBase = doc.Pages.Add()

        'Draw the page
        'DrawPage(page)

        'Dim pfxPath As String = Application.StartupPath + "\Demo.pfx"
        'Dim cert As New PdfCertificate(pfxPath, "e-iceblue")

        Dim cert As New PdfCertificate(bytecertificate.ToString, "abc123")
        Dim signature As New PdfSignature(doc, page, cert, "demo")
        signature.ContactInfo = "Haaaaa"
        signature.Certificated = True
        signature.DocumentPermissions = PdfCertificationFlags.AllowFormFill

        'Save pdf file.
        doc.Save("DigitalSignature.pdf")
        doc.Close()

        'Launching the Pdf file.
        Process.Start("DigitalSignature.pdf")
    End Sub


e-ice.PNG



and also where can i find the stored certificate ? because the post before i read it the certificate in the application folder (which i have comment it)
Code: Select all
 
'Dim pfxPath As String = Application.StartupPath + "\Demo.pfx"
Dim cert As New PdfCertificate(pfxPath, "e-iceblue")

blueeyeswhite
 
Posts: 15
Joined: Mon Jun 19, 2017 9:03 am

Mon Sep 11, 2017 9:18 am

Dear blueeyeswhite,

Thanks for your reply.
Please note the method I used was below.
Code: Select all
public PdfCertificate(byte[] signData, string password)

And bytecertificate is already byte, so please don't convert to string(bytecertificate.ToString), just use code below.
Code: Select all
Dim cert As New PdfCertificate(bytecertificate, "abc123")

And you could use the method File.WriteAllBytes("result.pfx", bytecertificate) to save it on disk.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Mon Sep 11, 2017 11:11 am

the reason i use tostring() because there's a line error of
value of type `byte()` cannot be converted to string


after i see your first code
Code: Select all
public PdfCertificate(byte[] signData, string password)

later when check it, the pdfcertificate only have 2 method either
1.png

11.png

blueeyeswhite
 
Posts: 15
Joined: Mon Jun 19, 2017 9:03 am

Tue Sep 12, 2017 1:53 am

Dear blueeyeswhite,

Thanks for your response.
The method I used is only available in commercial version. And from the screenshot, I guess you were using free version. You could firstly save the certificate on disk, then use the method "PdfCertificate(string pfxPath, string password)".
If there is any question, please let me know.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Fri Sep 15, 2017 8:38 am

Dear blueeyeswhite,

How is your issue now ?
Could you please give us some feedback at your convenience ?

Thanks,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Fri Sep 15, 2017 10:36 am

i can't perform the solution since i only use the free version.
iam gonna be awhile for this, since other project urgent
i'll try to ask again if iam gonna try this again

overall great response

blueeyeswhite
 
Posts: 15
Joined: Mon Jun 19, 2017 9:03 am

Mon Sep 18, 2017 1:49 am

Dear blueeyeswhite,

Thanks for your feedback.
Free version could solve your issue, please firstly save the certificate on disk, then use the method "PdfCertificate(string pfxPath, string password)". In addition, we don't have any plan to update the free version, so I suggest you use commercial version which has all fixes and improvements.
If there is any question, please let us know.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Return to Spire.PDF