CipherReference Clase

Definición

Representa el elemento <CipherReference> del cifrado XML. Esta clase no puede heredarse.

public ref class CipherReference sealed : System::Security::Cryptography::Xml::EncryptedReference
public sealed class CipherReference : System.Security.Cryptography.Xml.EncryptedReference
type CipherReference = class
    inherit EncryptedReference
Public NotInheritable Class CipherReference
Inherits EncryptedReference
Herencia
CipherReference

Ejemplos

En el ejemplo de código siguiente se crea una nueva instancia de CipherReference.

#using <System.Xml.dll>
#using <System.Security.dll>
#using <System.dll>

using namespace System;
using namespace System::Security::Cryptography::Xml;
using namespace System::Xml;
using namespace System::IO;

/// This sample used the EncryptedData class to create an encrypted data element
/// and write it to an XML file. It demonstrates the use of CipherReference.

[STAThread]
int main()
{
   
   //Create a URI string.
   String^ uri = "http://www.woodgrovebank.com/document.xml";
   
   // Create a Base64 transform. The input content retrieved from the
   // URI should be Base64-decoded before other processing.
   Transform^ base64 = gcnew XmlDsigBase64Transform;
   
   //Create a transform chain and add the transform to it.
   TransformChain^ tc = gcnew TransformChain;
   tc->Add( base64 );
   
   //Create <CipherReference> information.
   CipherReference ^ reference = gcnew CipherReference( uri,tc );
   
   // Create a new CipherData object using the CipherReference information.
   // Note that you cannot assign both a CipherReference and a CipherValue
   // to a CipherData object.
   CipherData ^ cd = gcnew CipherData( reference );
   
   // Create a new EncryptedData object.
   EncryptedData^ ed = gcnew EncryptedData;
   
   //Add an encryption method to the object.
   ed->Id = "ED";
   ed->EncryptionMethod = gcnew EncryptionMethod( "http://www.w3.org/2001/04/xmlenc#aes128-cbc" );
   ed->CipherData = cd;
   
   //Add key information to the object.
   KeyInfo^ ki = gcnew KeyInfo;
   ki->AddClause( gcnew KeyInfoRetrievalMethod( "#EK","http://www.w3.org/2001/04/xmlenc#EncryptedKey" ) );
   ed->KeyInfo = ki;
   
   // Create new XML document and put encrypted data into it.
   XmlDocument^ doc = gcnew XmlDocument;
   XmlElement^ encryptionPropertyElement = dynamic_cast<XmlElement^>(doc->CreateElement( "EncryptionProperty", EncryptedXml::XmlEncNamespaceUrl ));
   EncryptionProperty ^ ep = gcnew EncryptionProperty( encryptionPropertyElement );
   ed->AddProperty( ep );
   
   // Output the resulting XML information into a file.
   try
   {
      String^ path = "c:\\test\\MyTest.xml";
      File::WriteAllText( path, ed->GetXml()->OuterXml );
   }
   catch ( IOException^ e ) 
   {
      Console::WriteLine( "File IO error. {0}", e );
   }

}
using System;
using System.Security.Cryptography.Xml;
using System.Xml;
using System.IO;

/// This sample used the EncryptedData class to create an encrypted data element
/// and write it to an XML file. It demonstrates the use of CipherReference.
namespace EncryptedDataSample
{
    class Example
    {
        [STAThread]
        static void Main(string[] args)
        {
            //Create a URI string.
            String uri = "http://www.woodgrovebank.com/document.xml";
            // Create a Base64 transform. The input content retrieved from the
            // URI should be Base64-decoded before other processing.
            Transform base64 = new XmlDsigBase64Transform();
            //Create a transform chain and add the transform to it.
            TransformChain tc = new TransformChain();
            tc.Add(base64);
            //Create <CipherReference> information.
            CipherReference reference = new CipherReference(uri, tc);

            // Create a new CipherData object using the CipherReference information.
            // Note that you cannot assign both a CipherReference and a CipherValue
            // to a CipherData object.
            CipherData cd = new CipherData(reference);

            // Create a new EncryptedData object.
            EncryptedData ed = new EncryptedData();

            //Add an encryption method to the object.
            ed.Id = "ED";
            ed.EncryptionMethod = new EncryptionMethod("http://www.w3.org/2001/04/xmlenc#aes128-cbc");
            ed.CipherData = cd;

            //Add key information to the object.
            KeyInfo ki = new KeyInfo();
            ki.AddClause(new KeyInfoRetrievalMethod("#EK", "http://www.w3.org/2001/04/xmlenc#EncryptedKey"));
            ed.KeyInfo = ki;

            // Create new XML document and put encrypted data into it.
            XmlDocument doc = new XmlDocument();
            XmlElement encryptionPropertyElement = (XmlElement)doc.CreateElement("EncryptionProperty", EncryptedXml.XmlEncNamespaceUrl);
            EncryptionProperty ep = new EncryptionProperty(encryptionPropertyElement);
            ed.AddProperty(ep);

            // Output the resulting XML information into a file.
            try
            {
                string path = @"c:\test\MyTest.xml";

                File.WriteAllText(path, ed.GetXml().OuterXml);
            }
            catch (IOException e)
            {
                Console.WriteLine("File IO error. {0}", e);
            }
        }
    }
}
Imports System.Security.Cryptography.Xml
Imports System.Xml
Imports System.IO


'/ This sample used the EncryptedData class to create a EncryptedData element
'/ and write it to an XML file. It demonstrates the use of CipherReference.
Module Module1

    Sub Main()
        ' Create a URI string.
        Dim uri As String = "http://www.woodgrovebank.com/document.xml"
        ' Create a Base64 transform. The input content retrieved from the
        ' URI should be Base64-decoded before other processing.
        Dim base64 As Transform = New XmlDsigBase64Transform
        Dim tc As New TransformChain
        tc.Add(base64)
        ' Create <CipherReference> information.
        Dim reference As CipherReference = New CipherReference(uri, tc)

        ' Create a new CipherData object.
        ' Note that you cannot assign both a CipherReference and a CipherValue
        ' to a CipherData object.
        Dim cd As CipherData = New CipherData(Reference)

        ' Create a new EncryptedData object.
        Dim ed As New EncryptedData

        'Add an encryption method to the object.
        ed.Id = "ED"
        ed.EncryptionMethod = New EncryptionMethod("http://www.w3.org/2001/04/xmlenc#aes128-cbc")
        ed.CipherData = cd

        'Add key information to the object.
        Dim ki As New KeyInfo
        ki.AddClause(New KeyInfoRetrievalMethod("#EK", "http://www.w3.org/2001/04/xmlenc#EncryptedKey"))
        ed.KeyInfo = ki

        ' Create new XML document and put encrypted data into it.
        Dim doc As New XmlDocument
        Dim encryptionPropertyElement As XmlElement = CType(doc.CreateElement("EncryptionProperty", EncryptedXml.XmlEncNamespaceUrl), XmlElement)
        Dim ep As New EncryptionProperty(encryptionPropertyElement)
        ed.AddProperty(ep)

        ' Output the resulting XML information into a file.
        Dim path As String = "c:\test\MyTest.xml"
        File.WriteAllText(path, ed.GetXml().OuterXml)
    End Sub

End Module

Comentarios

Esta clase representa el <CipherReference> elemento del cifrado XML. Identifica un origen que, cuando se procesa, produce los datos cifrados.

El proceso siguiente obtiene los datos cifrados reales a los que hace referencia <CipherReference> . La <CipherReference> URI propiedad contiene un identificador uniforme de recursos (URI) que se desreferencia. Si el <CipherReference> elemento también contiene una cadena de transformación, los datos resultantes de desreferenciar el URI se transforman según se especifica para generar los datos cifrados. Por ejemplo, si los datos cifrados están codificados en base64 dentro de un documento XML, las transformaciones especificarían una expresión XPath seguida de una descodificación base64 para que se puedan extraer los datos cifrados.

La sintaxis del URI y las transformaciones es similar a la de las firmas digitales XML. Sin embargo, en las firmas digitales XML, el procesamiento de generación y validación comienza con los mismos datos de origen y realiza esa transformación en el mismo orden. En el cifrado XML, la aplicación de descifrado solo tiene los datos cifrados y las transformaciones especificadas. Las transformaciones se enumeran en el orden necesario para obtener los datos cifrados.

Nota De forma predeterminada, no se pueden desreferenciar referencias de cifrado de documentos con orígenes desconocidos, como archivos de un sitio web, porque la DocumentEvidence propiedad es null. Por ejemplo, cuando intenta descifrar un archivo que contiene un <CipherReference> elemento que hace referencia a un archivo en la Web, se produce una SecurityException excepción , incluso si un ensamblado de plena confianza realiza la solicitud.

Si está seguro de que los documentos que está descifrando pueden ser de confianza, puede cambiar este comportamiento para aplicaciones de plena confianza mediante el código siguiente:

Evidence ev = new Evidence();  
ev.AddHost (new Zone(SecurityZone.MyComputer));  
EncryptedXml exml = new EncryptedXml(doc, ev);  

Constructores

CipherReference()

Inicializa una nueva instancia de la clase CipherReference.

CipherReference(String)

Inicializa una nueva instancia de la clase CipherReference con el identificador uniforme de recursos (URI) especificado.

CipherReference(String, TransformChain)

Inicializa una nueva instancia de la clase CipherReference con el identificador uniforme de recursos (URI) especificado y la información de la cadena de transformación.

Propiedades

CacheValid

Obtiene un valor que indica si la caché es válida.

(Heredado de EncryptedReference)
ReferenceType

Obtiene o establece un tipo de referencia.

(Heredado de EncryptedReference)
TransformChain

Obtiene o establece la cadena de transformación de un objeto EncryptedReference.

(Heredado de EncryptedReference)
Uri

Obtiene o establece el identificador uniforme de recursos (URI) de un objeto EncryptedReference.

(Heredado de EncryptedReference)

Métodos

AddTransform(Transform)

Agrega un objeto Transform a la cadena de transformación actual de un objeto EncryptedReference.

(Heredado de EncryptedReference)
Equals(Object)

Determina si el objeto especificado es igual que el objeto actual.

(Heredado de Object)
GetHashCode()

Sirve como la función hash predeterminada.

(Heredado de Object)
GetType()

Obtiene el Type de la instancia actual.

(Heredado de Object)
GetXml()

Devuelve la representación XML de un objeto CipherReference.

LoadXml(XmlElement)

Carga información XML en el elemento <CipherReference> en cifrado XML.

MemberwiseClone()

Crea una copia superficial del Object actual.

(Heredado de Object)
ToString()

Devuelve una cadena que representa el objeto actual.

(Heredado de Object)

Se aplica a