CipherData Classe
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
Representa o <CipherData> elemento na encriptação XML. Esta classe não pode ser herdada.
public ref class CipherData sealed
public sealed class CipherData
type CipherData = class
Public NotInheritable Class CipherData
- Herança
-
CipherData
Exemplos
O exemplo de código seguinte usa a EncryptedData classe para criar um <EncryptedData> elemento que contém um <CipherData> elemento e depois escreve o XML num ficheiro XML.
using System;
using System.Security.Cryptography.Xml;
using System.Xml;
using System.IO;
/// This sample used the EncryptedData class to create a EncryptedData element
/// and write it to an XML file.
namespace EncryptedDataSample
{
class Sample1
{
[STAThread]
static void Main(string[] args)
{
// Create a new CipherData object.
CipherData cd = new CipherData();
// Assign a byte array to be the CipherValue. This is a byte array representing encrypted data.
cd.CipherValue = new byte[8];
// 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.
string path = @"c:\test\MyTest.xml";
File.WriteAllText(path,ed.GetXml().OuterXml);
//Console.WriteLine(ed.GetXml().OuterXml);
}
}
}
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.
Module EncryptedDataSample1
Sub Main()
' Create a new CipherData object.
Dim cd As New CipherData
' Assign a byte array to the CipherValue.
cd.CipherValue = New Byte(7) {}
' 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 Sub
End Module
Observações
A CipherData classe representa o <CipherData> elemento na encriptação XML. É um elemento obrigatório que fornece os dados encriptados. Deve conter os dados encriptados como texto codificado em base64 do <CipherValue> elemento, ou fornecer uma referência a uma localização externa contendo os dados encriptados usando o <CipherReference> elemento.
Em muitos casos, não precisa de criar diretamente uma nova instância da CipherData classe. As EncryptedXmlclasses , EncryptedData, e EncryptedKey criam instâncias para ti.
Note
Um CipherData objeto pode ter uma CipherReference propriedade ou uma CipherValue propriedade, mas não ambas. A CryptographicException é lançado se ambos forem atribuídos a um CipherData objeto.
Construtores
| Name | Description |
|---|---|
| CipherData() |
Inicializa uma nova instância da CipherData classe. |
| CipherData(Byte[]) |
Inicializa uma nova instância da CipherData classe usando um array de bytes como CipherValue valor. |
| CipherData(CipherReference) |
Inicializa uma nova instância da CipherData classe usando um CipherReference objeto. |
Propriedades
| Name | Description |
|---|---|
| CipherReference |
Recebe ou define o |
| CipherValue |
Recebe ou define o |
Métodos
| Name | Description |
|---|---|
| Equals(Object) |
Determina se o objeto especificado é igual ao objeto atual. (Herdado de Object) |
| GetHashCode() |
Serve como função de hash predefinida. (Herdado de Object) |
| GetType() |
Obtém o Type da instância atual. (Herdado de Object) |
| GetXml() |
Obtém os valores XML do CipherData objeto. |
| LoadXml(XmlElement) |
Carrega dados XML de um XmlElement para um CipherData objeto. |
| MemberwiseClone() |
Cria uma cópia superficial do atual Object. (Herdado de Object) |
| ToString() |
Devolve uma cadeia que representa o objeto atual. (Herdado de Object) |