Click here to Skip to main content
15,886,806 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi friends
I am trying to digitally sign the documents using the following code.
VB
Private Shared Function sign(ByVal input() As Byte, ByVal certificate As X509Certificate2) As Byte()
       'what is signed
       Dim content As ContentInfo = New ContentInfo(input)
       'who signs
       Dim signer As CmsSigner = New CmsSigner(certificate)
       ' represents a signed message
       Dim signedMessage As SignedCms = New SignedCms(content)
       'Sign the message.
       signedMessage.ComputeSignature(signer)
       'Serialize the signed message.
       Return signedMessage.Encode()
   End Function
   Private Shared Function encrypt(ByVal cert As X509Certificate2, ByVal input() As Byte) As Byte()
       'what is encrypted
       Dim content As ContentInfo = New ContentInfo(input)
       'represents an encrypted message
       Dim envelopedMessage As EnvelopedCms = New EnvelopedCms(content)
       'who can decrypt
       Dim recipient As CmsRecipient = New CmsRecipient(SubjectIdentifierType.SubjectKeyIdentifier, cert)
       'Encrypt the message.
       envelopedMessage.Encrypt(recipient)
       'Serialize the message.
       Return envelopedMessage.Encode()
   End Function
   Public Shared Function Signature(ByVal filename As String, ByVal certiID As Int32)
       'Getting the File Bytes
       Dim fileByte() As Byte = System.IO.File.ReadAllBytes(filename)
       'Getting The certificate
       Dim ds As System.Data.DataSet = GetCertificate(certiID)
       Dim byt() As Byte = New bal_MstCertificate().getcertificate(certiID).Tables(0).Rows(0)("CertCertificate")
       Dim pass As String = New bal_MstCertificate().getcertificate(certiID).Tables(0).Rows(0)("certPassWord")
       Dim myCertificate As X509Certificate2 = New X509Certificate2(byt, pass)
       'Signning the Data
       Dim signeddata() As Byte = sign(fileByte, myCertificate)
       Return encrypt(myCertificate, signeddata)
   End Function


On some machine it works but on Some machine it gives me following error

"an internal certificate chaining error" I am storing my certificate in the database
Please Helpe me in this issue
Posted

A look at your certificate chain is needed to see the problem. On Windows, you can see the application "Certificate Manager", "certmgr.msc" to see what' wrong in your certificate. See http://technet.microsoft.com/en-us/library/cc787544%28WS.10%29.aspx[^]. In brief, some certificates are registered in your system, trusted, untrusted, etc. You can look at "certificate path". A certificate property "issuer" should point to upper-level certificate. A certificate is a root certificate if its the issuer of itself. If this chain rules are not observed, you can see the problem you report.

For further detail, see:
http://en.wikipedia.org/wiki/Provable_security[^],
http://en.wikipedia.org/wiki/Public_key_certificate[^],
http://en.wikipedia.org/wiki/Public_key_infrastructure[^],
http://en.wikipedia.org/wiki/Certificate_authority[^];

see also: http://en.wikipedia.org/wiki/Self-signed_certificate[^].

—SA
 
Share this answer
 
v2
If you occured An internal certificate chaining error has occurred in your publish code this step will be follow- up

1.Click Start > Run.

2.Enter MMC and click OK.

3.Go to File > Add/Remove Snap-in.
4.Go to File > Add/Remove Snap-in.




5.Click Certificates, and select Add.




6.Select Computer Account, and click Next.






7.Select Local Computer and click Finish.




8.Click OK to close the Snap-ins window.




9.Double-click Certificates (local computer) to expand its view.

10.Right-click Intermediate Certification Authorities and select All Tasks àImport.




11.Complete the wizard to import the chain certificate. Browse to locate the chain certificate to be imported (*.cer).

12.Select Place all certificates in the following store and select the Intermediate Certificate Authorities store.




13.Click Next; then click Finish to complete the wizard.
Right-click Intermediate Certification Authorities and select Refresh. Expand the view for Intermediate Certification Authorities and look in the certificates directory to verify that the certificate is installed correctly.



or check this link http://www.entrust.net/knowledge-base/technote.cfm?tn=8166[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900