Sdílet prostřednictvím


CipherReference Třída

Definice

<CipherReference> Představuje prvek v šifrování XML. Tuto třídu nelze zdědit.

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
Dědičnost
CipherReference

Příklady

Následující příklad kódu vytvoří novou instanci CipherReference.

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

Poznámky

Tato třída představuje <CipherReference> prvek v šifrování XML. Identifikuje zdroj, který při zpracování poskytuje šifrovaná data.

Skutečná šifrovaná data, na která odkazuje, jsou <CipherReference> získána následujícím procesem. Vlastnost <CipherReference> URI obsahuje identifikátor URI (Uniform Resource Identifier), který je dereferenced. <CipherReference> Pokud element obsahuje také transformační řetězec, data výsledná z dereferencace identifikátoru URI se transformují tak, jak je uvedeno, aby vznikla šifrovaná data. Pokud jsou například šifrovaná data v dokumentu XML zakódovaná jako base64, transformace by určily výraz XPath následovaný dekódováním base64, aby bylo možné šifrovaná data extrahovat.

Syntaxe identifikátoru URI a transformací je podobná syntaxi digitálních podpisů XML. V digitálních podpisech XML však zpracování generování i ověřování začíná se stejnými zdrojovými daty a provádí tuto transformaci ve stejném pořadí. Při šifrování XML má dešifrovací aplikace pouze šifrovaná data a zadané transformace. Transformace se vyčíslují v pořadí potřebném k získání šifrovaných dat.

Poznámka Ve výchozím nastavení nelze odkazy na šifru dereference z dokumentů s neznámými zdroji, jako jsou soubory z webu, protože DocumentEvidence vlastnost má hodnotu null. Například při pokusu o dešifrování souboru obsahujícího <CipherReference> prvek, který odkazuje na soubor na webu, SecurityException je vyvolán, i když požadavek je proveden plně důvěryhodným sestavením.

Pokud jste si jistí, že dešifrované dokumenty můžou být důvěryhodné, můžete toto chování u plně důvěryhodných aplikací změnit pomocí následujícího kódu:

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

Konstruktory

Name Description
CipherReference()

Inicializuje novou instanci CipherReference třídy.

CipherReference(String, TransformChain)

Inicializuje novou instanci CipherReference třídy pomocí zadaného identifikátoru URI (Uniform Resource Identifier) a transformuje informace řetězu.

CipherReference(String)

Inicializuje novou instanci CipherReference třídy pomocí zadaného identifikátoru URI (Uniform Resource Identifier).

Vlastnosti

Name Description
CacheValid

Získá hodnotu, která určuje, zda je mezipaměť platná.

(Zděděno od EncryptedReference)
ReferenceType

Získá nebo nastaví typ odkazu.

(Zděděno od EncryptedReference)
TransformChain

Získá nebo nastaví transformační řetězec objektu EncryptedReference .

(Zděděno od EncryptedReference)
Uri

Získá nebo nastaví identifikátor URI (Uniform Resource Identifier) objektu EncryptedReference .

(Zděděno od EncryptedReference)

Metody

Name Description
AddTransform(Transform)

Transform Přidá objekt do aktuálního transformačního řetězce objektuEncryptedReference.

(Zděděno od EncryptedReference)
Equals(Object)

Určuje, zda je zadaný objekt roven aktuálnímu objektu.

(Zděděno od Object)
GetHashCode()

Slouží jako výchozí funkce hash.

(Zděděno od Object)
GetType()

Získá Type aktuální instance.

(Zděděno od Object)
GetXml()

Vrátí reprezentaci XML objektu CipherReference .

LoadXml(XmlElement)

Načte informace XML do elementu <CipherReference> v šifrování XML.

MemberwiseClone()

Vytvoří mělkou kopii aktuálního Object.

(Zděděno od Object)
ToString()

Vrátí řetězec, který představuje aktuální objekt.

(Zděděno od Object)

Platí pro