473,396 Members | 1,990 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Signing XML with a X509 Certificate


I'm trying to sign a XML with a X509 Certificate (Like an email), and store
it in a database. I want to include the certificate in the XML in order to
display the certificate properties (like click in the red insignia in a
signed email message)
for this purpose I'm using Visual Basic .Net 2003 with WSE 2.0 preview
edition

I succefully signed the XML with a certificate installed in my repository

the next step (for I am asking help) is to include certificate properties in
XML for displaying purposes, and any way to call the certificate properties
dialog with this info.
This is the code I use:

Imports System
Imports System.IO
Imports System.Security.Cryptography
Imports System.Security.Cryptography.Xml
Imports System.Xml
Imports Microsoft.Web.Services.Security.X509
Imports Microsoft.Web.Services.Security

Public Class Form1
Inherits System.Windows.Forms.Form

Private Sub SignXML
Dim store As X509CertificateStore
store =
X509CertificateStore.CurrentUserStore(X509Certific ateStore.MyStore)
Dim open As Boolean = store.OpenRead()

Dim oCertif As X509Certificate
Dim oCertificado As X509Certificate

For Each oCertif In store.Certificates
If InStr(oCertif.GetName, "Gustavo") <> 0 Then
oCertificado = oCertif
End If
Next
Dim signedXml As New System.security.Cryptography.xml.SignedXml
Dim key As RSA = oCertificado.Key
signedXml.SigningKey = key
Dim document As New XmlDocument
Dim node As XmlNode = document.CreateNode(XmlNodeType.Element, "",
"MyElement", "samples")
node.InnerText = "This is some text"
document.AppendChild(node)
Dim dataObject As New DataObject

dataObject.Data = document.ChildNodes
dataObject.Id = "MyObjectId"

' Add the data object to the signature.
signedXml.AddObject(dataObject)

' Create a reference to be able to package everything into the
' message.
Dim reference As New System.security.Cryptography.xml.Reference
reference.Uri = "#MyObjectId"

' Add it to the message.
signedXml.AddReference(reference)
' Add a KeyInfo.
Dim keyInfo As New KeyInfo
keyInfo.AddClause(New RSAKeyValue(key))
signedXml.KeyInfo = keyInfo
' Compute the signature.

signedXml.ComputeSignature()

' Get the XML representation of the signature.
Dim xmlSignature As XmlElement = signedXml.GetXml()
Debug.Write(xmlSignature.OuterXml)

Dim oWriter As New XmlTextWriter("C:\1.xml",
System.Text.Encoding.UTF8)
xmlSignature.WriteTo(oWriter)
oWriter.Close()
End Sub
Nov 12 '05 #1
1 12896

"Gustavo Quinteros" <gu*********@yahoo.com.ar> wrote in message
news:es**************@TK2MSFTNGP09.phx.gbl...


' Add a KeyInfo.
Dim keyInfo As New KeyInfo
keyInfo.AddClause(New RSAKeyValue(key))
signedXml.KeyInfo = keyInfo


Hi Gustavo, I am just beginer with XML Signature, but during last 3 dys a
managed to to what you intend to do.

try this, just after the code above
keyInfo.AddClause(New KeyInfoX509Data(oCertificado))

Muzzy
Nov 12 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: RBisch | last post by:
In order to sign a message, you can use a UserName token from the client (endpoint) , however must you use a X509 certificate to sign the response message from the service (endpoint) ? I am...
1
by: KlassifiedBBS | last post by:
Does anyone know if there is any sample code to create a x509 certificate out there - I'll buy a book if it has the code in it. I have spent a couple of days digging around in the...
1
by: | last post by:
Hi, I'd like to store X509 cetificates in a central location (file server, database, etc), and load them when needed, is it practical ? and in term of implementation, can this be achieved by...
0
by: steve perry | last post by:
I'm having trouble signing an soap message using an ssl certificate. The error message I get is "Cannot find the certificate and private key for decryption" I have tried using WSE 1.0 and WSE 2.0...
2
by: David G | last post by:
My company has a Webservice that is currently running in production. It is secured using SSL and clients are authenticated using X509 certificates. I am able to consume the Webservice methods in...
0
by: =?Utf-8?B?UmF2ZW4=?= | last post by:
I want to sign request messages with the private key of the X509 used by the client and the response messages must be signed by the server. Unfortunately, every binding in WCF seems to demand that...
0
by: AK | last post by:
Hello, I'm new to cryptography and I would just like to check that I'm doing the right thing when signing an XML file. I've got a PKCS#12 certificate (created using OpenSSL) which I'm loading...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.