PROBLEM CERTIFICATE X509

Discussion in 'ASP .Net' started by Jesus Suarez, Aug 27, 2007.

  1. Jesus Suarez

    Jesus Suarez Guest

    Hi all.

    I have a problem when signing the xml using x509 certificate created with
    private and public keys.

    Here is my code example



    getting certificate:

    Dim cert As X509Certificate2 = Nothing

    Dim store As New X509Store("My", StoreLocation.LocalMachine)

    Try

    store.Open(OpenFlags.ReadOnly Or OpenFlags.OpenExistingOnly)

    Dim CertCol As X509Certificate2Collection = store.Certificates

    Dim c As X509Certificate2

    For Each c In CertCol

    If c.Subject.Contains(CertificateSubject) Then

    cert = c

    Exit For

    End If

    Next c

    If cert Is Nothing Then

    Throw New CryptographicException("The certificate could not be found.")

    End If

    Finally

    store.Close()

    End Try

    Return cert



    signing xml:

    Dim MSCert As X509Certificate2 = cert 'GetCertificateBySubject(conf_Cer)

    If MSCert Is Nothing Then Throw New Exception("Cert is nothing")


    Dim signedXml As New SignedXml(Doc)

    signedXml.SigningKey = MSCert.PrivateKey

    Dim reference As New Reference()

    reference.Uri = ""

    Dim trns As XmlDsigC14NTransform = New XmlDsigC14NTransform()

    reference.AddTransform(trns)

    Dim env As New XmlDsigEnvelopedSignatureTransform()

    reference.AddTransform(env)

    signedXml.AddReference(reference)

    Dim keyInfo As New KeyInfo()

    keyInfo.AddClause(New KeyInfoX509Data(MSCert))

    signedXml.KeyInfo = keyInfo

    signedXml.ComputeSignature()

    Dim xmlDigitalSignature As XmlElement = signedXml.GetXml()

    Doc.DocumentElement.AppendChild(Doc.ImportNode(xmlDigitalSignature, True))



    The keyset does not exist exception happens here:


    Dim MSCert As X509Certificate2 = cert 'GetCertificateBySubject(conf_Cer)

    If MSCert Is Nothing Then Throw New Exception("Cert is nothing")


    Dim signedXml As New SignedXml(Doc)

    signedXml.SigningKey = MSCert.PrivateKey
    Jesus Suarez, Aug 27, 2007
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    521
  2. Replies:
    1
    Views:
    218
    Dominick Baier
    Sep 13, 2006
  3. Balint Kardos

    send X509 certificate to an Xmlrpc service under IIS7

    Balint Kardos, Aug 24, 2009, in forum: ASP .Net Security
    Replies:
    1
    Views:
    1,075
    Joe Kaplan
    Aug 24, 2009
  4. Keyset does not exist X509Certificate

    Keyset does not exist at Microsoft.Web.Services.Security.X509.X509

    Keyset does not exist X509Certificate, Jun 12, 2004, in forum: ASP .Net Web Services
    Replies:
    0
    Views:
    191
    Keyset does not exist X509Certificate
    Jun 12, 2004
  5. Jens Rügge

    Webservice, SSL, X509 certificate

    Jens Rügge, Dec 8, 2004, in forum: ASP .Net Web Services
    Replies:
    0
    Views:
    141
    Jens Rügge
    Dec 8, 2004
Loading...

Share This Page