M
maurolov78
Hi to all,
i'm making an ASP.Net site, where the user can ask a document, the web
server create it and digitally sign it with a digital certificate in a
USB token.
Working with the develop server in visual studio, when arrive the
first request, when i need to apply the digital sign, a form is throw
that ask the PIN. The next request not need to insert the PIN.
Either, with IIS, the PIN form cannot throw and then i cannot apply
the digital sign.
I have tried to insert the PIN by code, but i have founded no good
info.
Someone tell that it is not possible, someone with the same problem
have received no response.
I have founded some code in web, but i receive an error with no
documentation.
the code:
'open the store certificate
Dim mystore = New X509Store(StoreName.My, StoreLocation.LocalMachine)
mystore.Open(OpenFlags.ReadOnly)
Dim cert As New X509Certificate2
Dim certFounded As Boolean = False
'find the correct certificate
For Each cert In mystore.Certificates
If cert.Subject.Contains(MySubject) Then
certFounded = True
Exit For
End If
Next
If Not certFounded Then
Exit Function
End If
Dim signer As New Pkcs.CmsSigner()
Dim content As New Pkcs.ContentInfo(msgBytes)
Dim instance As New Pkcs.SignedCms(content, False)
'assign the certificate to the signer
signer.Certificate = cert
'compute the signature
instance.ComputeSignature(signer, False)
'encode the original message
Dim myCmsMessage As Byte()
myCmsMessage = instance.Encode
This is my original code. On
instance.ComputeSignature(signer, False)
the PIN form is throw
As i say before, in web i founded this code for pass the PIN
automatically
'encode the PIN string
Dim pwstr As New System.Security.SecureString()
pwstr.AppendChar("1")
pwstr.AppendChar("2")
pwstr.AppendChar("3")
pwstr.AppendChar("4")
pwstr.AppendChar("5")
pwstr.AppendChar("6")
pwstr.AppendChar("7")
pwstr.AppendChar("8")
'create a csp parameters
Dim cspparams As New CspParameters(1, MioProvider)
'assign the encoded password to the parameters
cspparams.KeyPassword = pwstr
'now i chancge the signer construct
'Dim signer As New Pkcs.CmsSigner()
Dim signer As New Pkcs.CmsSigner(cspparams)
Now a cryptographicException is throw
"Operation Complete" (mah!)
and in stackTrace:
in System.Security.Cryptography.Pkcs.PkcsUtils.CreateDummyCertificate
(CspParameters parameters)
in System.Security.Cryptography.Pkcs.CmsSigner..ctor(CspParameters
parameters)
etc....
I hev no found nothing about this exception
Someone can suggest a procedure to skip theese problems?
I need to show the PIN form or pass the PIN by code
Thanks to all
i'm making an ASP.Net site, where the user can ask a document, the web
server create it and digitally sign it with a digital certificate in a
USB token.
Working with the develop server in visual studio, when arrive the
first request, when i need to apply the digital sign, a form is throw
that ask the PIN. The next request not need to insert the PIN.
Either, with IIS, the PIN form cannot throw and then i cannot apply
the digital sign.
I have tried to insert the PIN by code, but i have founded no good
info.
Someone tell that it is not possible, someone with the same problem
have received no response.
I have founded some code in web, but i receive an error with no
documentation.
the code:
'open the store certificate
Dim mystore = New X509Store(StoreName.My, StoreLocation.LocalMachine)
mystore.Open(OpenFlags.ReadOnly)
Dim cert As New X509Certificate2
Dim certFounded As Boolean = False
'find the correct certificate
For Each cert In mystore.Certificates
If cert.Subject.Contains(MySubject) Then
certFounded = True
Exit For
End If
Next
If Not certFounded Then
Exit Function
End If
Dim signer As New Pkcs.CmsSigner()
Dim content As New Pkcs.ContentInfo(msgBytes)
Dim instance As New Pkcs.SignedCms(content, False)
'assign the certificate to the signer
signer.Certificate = cert
'compute the signature
instance.ComputeSignature(signer, False)
'encode the original message
Dim myCmsMessage As Byte()
myCmsMessage = instance.Encode
This is my original code. On
instance.ComputeSignature(signer, False)
the PIN form is throw
As i say before, in web i founded this code for pass the PIN
automatically
'encode the PIN string
Dim pwstr As New System.Security.SecureString()
pwstr.AppendChar("1")
pwstr.AppendChar("2")
pwstr.AppendChar("3")
pwstr.AppendChar("4")
pwstr.AppendChar("5")
pwstr.AppendChar("6")
pwstr.AppendChar("7")
pwstr.AppendChar("8")
'create a csp parameters
Dim cspparams As New CspParameters(1, MioProvider)
'assign the encoded password to the parameters
cspparams.KeyPassword = pwstr
'now i chancge the signer construct
'Dim signer As New Pkcs.CmsSigner()
Dim signer As New Pkcs.CmsSigner(cspparams)
Now a cryptographicException is throw
"Operation Complete" (mah!)
and in stackTrace:
in System.Security.Cryptography.Pkcs.PkcsUtils.CreateDummyCertificate
(CspParameters parameters)
in System.Security.Cryptography.Pkcs.CmsSigner..ctor(CspParameters
parameters)
etc....
I hev no found nothing about this exception
Someone can suggest a procedure to skip theese problems?
I need to show the PIN form or pass the PIN by code
Thanks to all