语言

CipherReference 类

定义

表示 <CipherReference> XML 加密中的元素。 此类不能被继承。

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
继承
CipherReference

示例

下面的代码示例创建一个新实例 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

注解

此类表示 <CipherReference> XML 加密中的元素。 它标识一个源,该源在处理时会生成加密的数据。

以下过程获取由 <CipherReference> 该数据引用的实际加密数据。 该 <CipherReference> URI 属性包含取消引用的统一资源标识符(URI)。 <CipherReference>如果该元素还包含转换链,则根据指定方式转换 URI 导致的数据将转换为生成加密数据。 例如,如果在 XML 文档中对加密数据进行 base64 编码,转换将指定 XPath 表达式,后跟 base64 解码,以便提取加密的数据。

URI 和转换的语法类似于 XML 数字签名的语法。 但是,在 XML 数字签名中,生成和验证处理都以相同的源数据开头,并按相同的顺序执行转换。 在 XML 加密中,解密应用程序只有加密数据和指定的转换。 转换按获取加密数据所需的顺序进行枚举。

注意 默认情况下,无法从具有未知源的文档(例如网站中的文件)取消引用密码引用,因为 DocumentEvidence 该属性为 null。 例如,当你尝试解密包含引用 <CipherReference> Web 上的文件的元素的文件时,即使请求是由完全受信任的程序集发出的,也会引发 a SecurityException 。

如果确定可以信任解密的文档,则可以使用以下代码更改完全受信任的应用程序的此行为:

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

构造函数

名称 说明
CipherReference()

初始化 CipherReference 类的新实例。

CipherReference(String, TransformChain)

使用指定的统一资源标识符(URI)和转换链信息初始化类的新实例 CipherReference 。

CipherReference(String)

使用指定的统一资源标识符(URI)初始化类的新实例 CipherReference 。

属性

名称 说明
CacheValid

获取一个值,该值指示缓存是否有效。

(继承自 EncryptedReference)
ReferenceType

获取或设置引用类型。

(继承自 EncryptedReference)
TransformChain

获取或设置对象的转换链 EncryptedReference 。

(继承自 EncryptedReference)
Uri

获取或设置对象的统一 EncryptedReference 资源标识符(URI)。

(继承自 EncryptedReference)

方法

名称 说明
AddTransform(Transform)

将对象 Transform 添加到对象的当前转换链 EncryptedReference 。

(继承自 EncryptedReference)
Equals(Object)

确定指定的对象是否等于当前对象。

(继承自 Object)
GetHashCode()

用作默认哈希函数。

(继承自 Object)
GetType()

获取当前实例的 Type。

(继承自 Object)
GetXml()

返回对象的 XML 表示形式 CipherReference 。

LoadXml(XmlElement)

将 XML 信息加载到 <CipherReference> XML 加密中的元素中。

MemberwiseClone()

创建当前 Object的浅表副本。

(继承自 Object)
ToString()

返回一个表示当前对象的字符串。

(继承自 Object)

适用于