CipherReference Classe
Definizione
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Rappresenta l'elemento <CipherReference> nella crittografia XML. Questa classe non può essere ereditata.
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
- Ereditarietà
Esempio
Nell'esempio di codice seguente viene creata una nuova istanza di 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
Commenti
Questa classe rappresenta l'elemento <CipherReference> nella crittografia XML. Identifica un'origine che, durante l'elaborazione, restituisce i dati crittografati.
I dati crittografati effettivi a cui fa riferimento l'oggetto <CipherReference> vengono ottenuti dal processo seguente. La <CipherReference> URI proprietà contiene un URI (Uniform Resource Identifier) dereferenziato. Se l'elemento <CipherReference> contiene anche una catena di trasformazioni, i dati risultanti dalla dereferenziazione dell'URI vengono trasformati come specificato per produrre i dati crittografati. Ad esempio, se i dati crittografati sono codificati in base64 all'interno di un documento XML, le trasformazioni specificano un'espressione XPath seguita da una decodifica base64 in modo che i dati crittografati possano essere estratti.
La sintassi dell'URI e delle trasformazioni è simile a quella delle firme digitali XML. Tuttavia, nelle firme digitali XML, sia l'elaborazione di generazione che di convalida iniziano con gli stessi dati di origine ed eseguono tale trasformazione nello stesso ordine. Nella crittografia XML l'applicazione di decrittografia include solo i dati crittografati e le trasformazioni specificate. Le trasformazioni vengono enumerate nell'ordine necessario per ottenere i dati crittografati.
Nota Per impostazione predefinita, non è possibile dereferenziare riferimenti di crittografia da documenti con origini sconosciute, ad esempio i file di un sito Web, perché la DocumentEvidence proprietà è null. Ad esempio, quando si tenta di decrittografare un file contenente un <CipherReference> elemento che fa riferimento a un file sul Web, viene generato un SecurityException oggetto , anche se la richiesta viene effettuata da un assembly completamente attendibile.
Se si è certi che i documenti che si stanno decrittografando possono essere attendibili, è possibile modificare questo comportamento per le applicazioni completamente attendibili usando il codice seguente:
Evidence ev = new Evidence();
ev.AddHost (new Zone(SecurityZone.MyComputer));
EncryptedXml exml = new EncryptedXml(doc, ev);
Costruttori
| Nome | Descrizione |
|---|---|
| CipherReference() |
Inizializza una nuova istanza della classe CipherReference. |
| CipherReference(String, TransformChain) |
Inizializza una nuova istanza della CipherReference classe utilizzando l'URI (Uniform Resource Identifier) specificato e le informazioni sulla catena di trasformazione. |
| CipherReference(String) |
Inizializza una nuova istanza della CipherReference classe utilizzando l'URI (Uniform Resource Identifier) specificato. |
Proprietà
| Nome | Descrizione |
|---|---|
| CacheValid |
Ottiene un valore che indica se la cache è valida. (Ereditato da EncryptedReference) |
| ReferenceType |
Ottiene o imposta un tipo di riferimento. (Ereditato da EncryptedReference) |
| TransformChain |
Ottiene o imposta la catena di trasformazioni di un EncryptedReference oggetto . (Ereditato da EncryptedReference) |
| Uri |
Ottiene o imposta l'URI (Uniform Resource Identifier) di un EncryptedReference oggetto . (Ereditato da EncryptedReference) |
Metodi
| Nome | Descrizione |
|---|---|
| AddTransform(Transform) |
Aggiunge un Transform oggetto alla catena di trasformazione corrente di un EncryptedReference oggetto . (Ereditato da EncryptedReference) |
| Equals(Object) |
Determina se l'oggetto specificato è uguale all'oggetto corrente. (Ereditato da Object) |
| GetHashCode() |
Funge da funzione hash predefinita. (Ereditato da Object) |
| GetType() |
Ottiene il Type dell'istanza corrente. (Ereditato da Object) |
| GetXml() |
Restituisce la rappresentazione XML di un CipherReference oggetto . |
| LoadXml(XmlElement) |
Carica le informazioni XML nell'elemento |
| MemberwiseClone() |
Crea una copia superficiale del Objectcorrente. (Ereditato da Object) |
| ToString() |
Restituisce una stringa che rappresenta l'oggetto corrente. (Ereditato da Object) |