Xml Dsign

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Alf
    New Member
    • Sep 2007
    • 3

    Xml Dsign

    Hi,
    I'm trying to create signed XML document with SignedXml class. I'm using Framework 1.1 and WSE 2.0 to get certificate. I get certificate from LOCAL_MACHINE\M y store but when I try get private key "oCertificado.K ey.ToXmlString( True)" I get the next exception:

    "An unhandled exception of type 'System.NotSupp ortedException'
    occurred in microsoft.web.s ervices2.dll Additional information: Export of private parameters is not supported"


    Code:
    Protected Function ObtenerCertificado() As X509Certificate
    
            Dim store As X509CertificateStore
    
            Try
    
                store = X509CertificateStore.LocalMachineStore       (X509CertificateStore.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, "DESARROLLO.MINHAC.AGE") <> 0 Then
                        oCertificado = oCertif
                    End If
                Next
    
                Return oCertificado
    
            Catch ex As Exception
                Me.iEstadoOperacion = Me.AYUDA
                Me.sMsgCliente = ex.Message
                Me.sMsgCliente = Me.sMsgCliente.Replace("'", "")
            Finally
                store.Close()
                store = Nothing
            End Try
    
        End Function
    
     Protected Function FirmarXml(ByVal oCertificado As X509Certificate, ByVal DocumentoXml As XmlDocument) As XmlElement
    
            Dim signedXml As New System.security.Cryptography.xml.SignedXml
            Dim dataObject As New DataObject
    
            Try
             
                signedXml.SigningKey = oCertificado.Key
    
                Me.iEstadoOperacion = Me.AYUDA
                Me.sMsgCliente = oCertificado.Key.ToXmlString(False)
                Exit Function
    
                Dim document As New XmlDocument
                Dim node As XmlNode = document.CreateNode(XmlNodeType.Element, "", "MyElement", "samples")
    
                node.InnerText = DocumentoXml.OuterXml.ToString
                document.AppendChild(node)
    
                dataObject.Data = document.ChildNodes
                dataObject.Id = "MyObjectId"
    
                signedXml.AddObject(dataObject)
    
                ' Creamos una referencia
                Dim reference As New System.security.Cryptography.xml.Reference
                reference.Uri = "#MyObjectId"
    
                'AƱadimos la referencia.
                signedXml.AddReference(reference)
    
                'AƱadimos KeyInfo.
                Dim keyInfo As New KeyInfo
                keyInfo.AddClause(New RSAKeyValue(oCertificado.Key))
                keyInfo.AddClause(New KeyInfoX509Data(oCertificado))
                signedXml.KeyInfo = keyInfo
    
                'Firmamos
                signedXml.ComputeSignature()
    
                Return signedXml.GetXml()
    
            Catch ex As Exception
                Me.iEstadoOperacion = Me.AYUDA
                Me.sMsgCliente = ex.Message
                Me.sMsgCliente = Me.sMsgCliente.Replace("'", "")
            Finally
                dataObject = Nothing
                signedXml = Nothing
            End Try
    
        End Function
    Somebody know why is this exception?

    Thank you very much.
  • kenobewan
    Recognized Expert Specialist
    • Dec 2006
    • 4871

    #2
    Does it give you a line number? Thanks.

    Comment

    • Alf
      New Member
      • Sep 2007
      • 3

      #3
      Yes the exception is in line 43,
      "Me.sMsgCli ente = oCertificado.Ke y.ToXmlString(T rue)"

      Thanks.

      Comment

      Working...