Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > PROBLEM CERTIFICATE X509

Reply
Thread Tools

PROBLEM CERTIFICATE X509

 
 
Jesus Suarez
Guest
Posts: n/a
 
      08-27-2007
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(xml DigitalSignature, 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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
send X509 certificate to an Xmlrpc service under IIS7 Balint Kardos ASP .Net Security 1 08-24-2009 03:03 PM
importing public key from X509 certificate kodurradhika@gmail.com ASP .Net Security 1 09-13-2006 09:20 AM
To get from the browser (web client), the server X509 certificate used in an SSL established session paxtra@gmail.com Java 0 08-02-2006 08:02 AM
Webservice, SSL, X509 certificate Jens Rügge ASP .Net Web Services 0 12-08-2004 12:35 PM
Keyset does not exist at Microsoft.Web.Services.Security.X509.X509 Keyset does not exist X509Certificate ASP .Net Web Services 0 06-12-2004 01:07 AM



Advertisments