Scott,
You can use the X509CertificateStore object from WSE 1.0
(Microsoft.Web.Services.Security.X509) to open the desired cert store and
extract your cert. Then assign the cert key to an RSA object from
System.Security.Cryptography.
Dim sCertSubject As String
Dim oStore As X509CertificateStore
Dim oCert As Microsoft.Web.Services.Security.X509.X509Certificate = Nothing
Dim oCerts As X509CertificateCollection
Dim oKey As RSA
Dim xmlManifest As XmlDocument
Dim signedXml As SignedXml
Dim refManifest As Reference
sCertSubject = "some subject string"
' get the key from the cert store
oStore =
X509CertificateStore.LocalMachineStore(X509CertificateStore.MyStore)
oStore.OpenRead()
' find the subject
oCerts = oStore.FindCertificateBySubjectName(sCertSubject)
' make sure you found the cert you were looking for...
If oCerts.Count > 0 Then ' Obtain the first matching certificate.
oCert = CType(oCerts(0),
Microsoft.Web.Services.Security.X509.X509Certificate)
Else ' No certificates matched the search criteria.
' throw an exception, etc...
End If
' close the X.509 certificate store.
oStore.Close()
' create the RSA object and assign the cert key
oKey = oCert.Key
Now use the SignedXML object to create your signature...
' load the XML into a DOM
xmlManifest = New XmlDocument
xmlManifest.Load("manifest.xml")
' create the SignedXml object and assign the key
signedXml = New SignedXml(xmlManifest)
signedXml.SigningKey = oKey
' add Reference, transformation, envelope, etc. to the signed XML node per
your requirements...
refManifest = New Reference
refManifest.Uri = ""
Dim env As New XmlDsigEnvelopedSignatureTransform
refManifest.AddTransform(env)
Dim trans As New XmlDsigC14NTransform
refManifest.AddTransform(trans)
signedXml.AddReference(refManifest)
' add KeyInfo object per your requirements...
Dim keyInfo As New KeyInfo
keyInfo.AddClause(New RSAKeyValue(oKey))
signedXml.KeyInfo = keyInfo
' calculate signature
signedXml.ComputeSignature()
' get signature from SignedXml object
Dim xmlDigitalSignature As XmlElement = signedXml.GetXml()
' add the signature element to the orginal manifest xml using AppendChild,
InsertAfter, etc...
HTH,
- Paul
[quoted text, click to view] "Scott" <sbusse144@yahoo.com> wrote in message
news:eEPpbeZeEHA.3792@TK2MSFTNGP09.phx.gbl...
> Anyone have an idea how to sign a manifest.xml file with an X.509
> certificate without having to use that buggy XMLSign utility?
>
>