CAPICOM problem:cannot access certificate store

From: edwards (edwards_at_discussions.microsoft.com)
Date: 05/27/05


Date: Fri, 27 May 2005 02:30:02 -0700

Hello, Could you help me ?
I am developing a web application that needs to create a signature. To do
this I am using CAPICOM but I have a problem:
When I try to obtain the certificate from a certificate store but I get a
exception which says that the Certificate store is empty (this is not true,
of course):

System.Runtime.InteropServices.COMException(0x80880231):The certificate
store does not contain any certificate.
 
But, when I use the same code in windows application, it runs ok.
I use CAPICOM2.0.0.3,runs on Windows XP,IIS 5.1
 
What is hapenning? How can i solve it?

ahh.. if I could not solve my problem..
 
The code is listed following, it's from MSDN sample code:
 
 
 Sub Signfile(ByVal InputFileName As String, ByVal _
     OutputFileName As String)
 
        'On Error GoTo ErrorHandler
        Dim content As String
        Dim signature As String
        Dim MyStore As New Store()
        Dim Signobj As New SignedData()
        Dim Signer As New Signer()
 
        ' NOTE: the name 'Attribute' is not a unique name
        ' and must be preceded by 'CAPICOM.'
        Dim SigningTime As New CAPICOM.Attribute()
 
        ' Open the MY store and retrieve the first certificate from the
        ' Store. The signing operation will only work if this
        ' certificate is valid and has access to the signer's private key.
        MyStore.Open(CAPICOM_STORE_LOCATION.CAPICOM_CURRENT_USER_STORE,
"MY", CAPICOM_STORE_OPEN_MODE.CAPICOM_STORE_OPEN_READ_ONLY)
        'Signer.Certificate = MyStore.Certificates.Item(1)
 
        ' Open the input file and read the content to be signed from the file.
        FileOpen(1, InputFileName, OpenMode.Input)
        While Not EOF(1)
            content = LineInput(1)
        End While
 
        FileClose(1)
 
        ' Set the content to be signed.
        Signobj.Content = content
 
        ' Save the time the data was signed as a signer attribute.
        SigningTime.Name =
CAPICOM_ATTRIBUTE.CAPICOM_AUTHENTICATED_ATTRIBUTE_SIGNING_TIME
        SigningTime.Value = Now
        Signer.AuthenticatedAttributes.Add(SigningTime)
 
        ' Sign the content using the signer's private key.
        ' The 'True' parameter indicates that the content signed is not
        ' included in the signature string.
        'signature = Signobj.Sign(Signer, True)
        signature = Signobj.Sign(Nothing, True)
        FileOpen(2, OutputFileName, OpenMode.Output)
        Write(2, signature)
        FileClose(2)
 
        'MsgBox("Signature done - Saved to file" & OutputFileName)
        Signobj = Nothing
        MyStore = Nothing
        Signer = Nothing
        SigningTime = Nothing
 
        Exit Sub
 
        'ErrorHandler:
        ' If Err.Number > 0 Then
        ' MsgBox("Visual Basic error found:" & Err.Description)
        ' Else
        ' MsgBox("CAPICOM error found : " & Err.Number)
        ' End If
    End Sub



Relevant Pages

  • RE: CAPICOM problem:cannot access certificate store
    ... > When I try to obtain the certificate from a certificate store but I get a ... > exception which says that the Certificate store is empty (this is not true, ... > OutputFileName As String) ... > End Sub ...
    (microsoft.public.dotnet.security)
  • Re: Obtaining X.509 Certifcates
    ... Certmgr.exe works with two types of certificate stores: ... and CRLs from your disk to a certificate store. ... Also by default, the ASP.NET service runs under the ASPNET account, ... Set the userName attribute of the element to specify ...
    (microsoft.public.dotnet.framework.webservices.enhancements)
  • Re: Obtaining X.509 Certifcates
    ... > Certmgr.exe works with two types of certificate stores: ... > and CRLs from your disk to a certificate store. ... > In order for WSE to obtain the X.509 private key from the local ... > Also by default, the ASP.NET service runs under the ASPNET account, ...
    (microsoft.public.dotnet.framework.webservices.enhancements)
  • Re: Deploying Root Cert via GPO
    ... certificate store, and by mmc, you are accessing current computer's ... Windows Server - Directory Services ... > certificate issued by the above root cert. ...
    (microsoft.public.windows.group_policy)
  • Re: Import Sec Certificate using script
    ... I noticed that you have opened a new post in other newsgroup. ... -addstore Adds a certificate to a certificate store. ... -enterprise Uses the local computer Enterprise registry certificate store. ... CertificateStoreName Specifies one of the following store names: ...
    (microsoft.public.windows.inetexplorer.ie6.browser)