Early Preview
This is currently very much a preview. Please feel free to try things out,
but don't be upset if anything is not yet working. Feedback is welcome over on our
GitHub Dicussions page.
class System.​Security.​Cryptography.​Xml.​EncryptedXml
Assembly: System.Security.Cryptography.Xml
Inheritance: object → EncryptedXml
Represents the process model for implementing XML encryption.
Fields and Constants
public const
string
XmlEncAES128KeyWrapUrl
Represents the namespace Uniform Resource Identifier (URI) for the 128-bit Advanced Encryption Standard (AES) Key Wrap algorithm (also known as the Rijndael Key Wrap algorithm). This field is constant.
public const
string
XmlEncAES128Url
Represents the namespace Uniform Resource Identifier (URI) for the 128-bit Advanced Encryption Standard (AES) algorithm (also known as the Rijndael algorithm). This field is constant.
public const
string
XmlEncAES192KeyWrapUrl
Represents the namespace Uniform Resource Identifier (URI) for the 192-bit Advanced Encryption Standard (AES) Key Wrap algorithm (also known as the Rijndael Key Wrap algorithm). This field is constant.
public const
string
XmlEncAES192Url
Represents the namespace Uniform Resource Identifier (URI) for the 192-bit Advanced Encryption Standard (AES) algorithm (also known as the Rijndael algorithm). This field is constant.
public const
string
XmlEncAES256KeyWrapUrl
Represents the namespace Uniform Resource Identifier (URI) for the 256-bit Advanced Encryption Standard (AES) Key Wrap algorithm (also known as the Rijndael Key Wrap algorithm). This field is constant.
public const
string
XmlEncAES256Url
Represents the namespace Uniform Resource Identifier (URI) for the 256-bit Advanced Encryption Standard (AES) algorithm (also known as the Rijndael algorithm). This field is constant.
public const
string
XmlEncDESUrl
Represents the namespace Uniform Resource Identifier (URI) for the Digital Encryption Standard (DES) algorithm. This field is constant.
public const
string
XmlEncElementContentUrl
Represents the namespace Uniform Resource Identifier (URI) for XML encryption element content. This field is constant.
public const
string
XmlEncElementUrl
Represents the namespace Uniform Resource Identifier (URI) for an XML encryption element. This field is constant.
public const
string
XmlEncEncryptedKeyUrl
Represents the namespace Uniform Resource Identifier (URI) for the XML encryption <see langword="<EncryptedKey>" /> element. This field is constant.
public const
string
XmlEncNamespaceUrl
Represents the namespace Uniform Resource Identifier (URI) for XML encryption syntax and processing. This field is constant.
public const
string
XmlEncRSA15Url
Represents the namespace Uniform Resource Identifier (URI) for the RSA Public Key Cryptography Standard (PKCS) Version 1.5 algorithm. This field is constant.
public const
string
XmlEncRSAOAEPUrl
Represents the namespace Uniform Resource Identifier (URI) for the RSA Optimal Asymmetric Encryption Padding (OAEP) encryption algorithm. This field is constant.
public const
string
XmlEncSHA256Url
Represents the namespace Uniform Resource Identifier (URI) for the SHA-256 algorithm. This field is constant.
public const
string
XmlEncSHA512Url
Represents the namespace Uniform Resource Identifier (URI) for the SHA-512 algorithm. This field is constant.
public const
string
XmlEncTripleDESKeyWrapUrl
Represents the namespace Uniform Resource Identifier (URI) for the TRIPLEDES key wrap algorithm. This field is constant.
public const
string
XmlEncTripleDESUrl
Represents the namespace Uniform Resource Identifier (URI) for the Triple DES algorithm. This field is constant.
Properties
DocumentEvidence
Gets or sets the evidence of the <see cref="T:System.Xml.XmlDocument" /> object from which the <see cref="T:System.Security.Cryptography.Xml.EncryptedXml" /> object is constructed.
Encoding
Gets or sets the encoding used for XML encryption.
public
CipherMode
Mode
Gets or sets the cipher mode used for XML encryption.
public
PaddingMode
Padding
Gets or sets the padding mode used for XML encryption.
public
string
Recipient
Gets or sets the recipient of the encrypted key information.
Resolver
Gets or sets the <see cref="T:System.Xml.XmlResolver" /> object used by the Document Object Model (DOM) to resolve external XML references.
public
int
XmlDSigSearchDepth
Gets or sets the XML digital signature recursion depth to prevent infinite recursion and stack overflow. This might happen if the digital signature XML contains the URI that then points back to the original XML.
Methods
public
void
AddKeyNameMapping​(string keyName,
object keyObject)
Defines a mapping between a key name and a symmetric key or an asymmetric key.
keyName
The name to map to <paramref name="keyObject" /> .
keyObject
The symmetric key to map to <paramref name="keyName" /> .
public
void
ClearKeyNameMappings​()
Resets all key name mapping.
public
byte[]
DecryptData​(EncryptedData encryptedData,
SymmetricAlgorithm symmetricAlgorithm)
Decrypts an <see langword="<EncryptedData>" /> element using the specified symmetric algorithm.
Returns A byte array that contains the raw decrypted plain text.
encryptedData
The data to decrypt.
symmetricAlgorithm
The symmetric key used to decrypt <paramref name="encryptedData" /> .
public
void
DecryptDocument​()
Decrypts all <see langword="<EncryptedData>" /> elements of the XML document that were specified during initialization of the <see cref="T:System.Security.Cryptography.Xml.EncryptedXml" /> class.
public
byte[]
DecryptEncryptedKey​(EncryptedKey encryptedKey)
Determines the key represented by the <see cref="T:System.Security.Cryptography.Xml.EncryptedKey" /> element.
Returns A byte array that contains the key.
encryptedKey
The <see cref="T:System.Security.Cryptography.Xml.EncryptedKey" /> object that contains the key to retrieve.
public static
byte[]
DecryptKey​(byte[] keyData,
RSA rsa,
bool useOAEP)
Decrypts an <see langword="<EncryptedKey>" /> element using an asymmetric algorithm.
Returns A byte array that contains the plain text key.
keyData
An array of bytes that represents an encrypted <see langword="<EncryptedKey>" /> element.
rsa
The asymmetric key used to decrypt <paramref name="keyData" /> .
useOAEP
A value that specifies whether to use Optimal Asymmetric Encryption Padding (OAEP).
public static
byte[]
DecryptKey​(byte[] keyData,
SymmetricAlgorithm symmetricAlgorithm)
Decrypts an <see langword="<EncryptedKey>" /> element using a symmetric algorithm.
Returns A byte array that contains the plain text key.
keyData
An array of bytes that represents an encrypted <see langword="<EncryptedKey>" /> element.
symmetricAlgorithm
The symmetric key used to decrypt <paramref name="keyData" /> .
public
EncryptedData
Encrypt​(Xml.​XmlElement inputElement,
X509Certificates.​X509Certificate2 certificate)
Encrypts the outer XML of an element using the specified X.509 certificate.
Returns An <see cref="T:System.Security.Cryptography.Xml.EncryptedData" /> element that represents the encrypted XML data.
inputElement
The XML element to encrypt.
certificate
The X.509 certificate to use for encryption.
public
EncryptedData
Encrypt​(Xml.​XmlElement inputElement,
string keyName)
Encrypts the outer XML of an element using the specified key in the key mapping table.
Returns An <see cref="T:System.Security.Cryptography.Xml.EncryptedData" /> object that represents the encrypted XML data.
inputElement
The XML element to encrypt.
keyName
A key name that can be found in the key mapping table.
public
byte[]
EncryptData​(byte[] plaintext,
SymmetricAlgorithm symmetricAlgorithm)
Encrypts data in the specified byte array using the specified symmetric algorithm.
Returns A byte array of encrypted data.
plaintext
The data to encrypt.
symmetricAlgorithm
The symmetric algorithm to use for encryption.
public
byte[]
EncryptData​(Xml.​XmlElement inputElement,
SymmetricAlgorithm symmetricAlgorithm,
bool content)
Encrypts the specified element or its contents using the specified symmetric algorithm.
Returns A byte array that contains the encrypted data.
inputElement
The element or its contents to encrypt.
symmetricAlgorithm
The symmetric algorithm to use for encryption.
content
<see langword="true" /> to encrypt only the contents of the element; <see langword="false" /> to encrypt the entire element.
public static
byte[]
EncryptKey​(byte[] keyData,
RSA rsa,
bool useOAEP)
Encrypts the key that a recipient uses to decrypt an <see langword="<EncryptedData>" /> element.
Returns A byte array that represents the encrypted value of the <paramref name="keyData" /> parameter.
keyData
The key to encrypt.
rsa
The asymmetric key used to encrypt <paramref name="keyData" /> .
useOAEP
A value that specifies whether to use Optimal Asymmetric Encryption Padding (OAEP).
public static
byte[]
EncryptKey​(byte[] keyData,
SymmetricAlgorithm symmetricAlgorithm)
Encrypts a key using a symmetric algorithm that a recipient uses to decrypt an <see langword="<EncryptedData>" /> element.
Returns A byte array that represents the encrypted value of the <paramref name="keyData" /> parameter.
keyData
The key to encrypt.
symmetricAlgorithm
The symmetric key used to encrypt <paramref name="keyData" /> .
public
byte[]
GetDecryptionIV​(EncryptedData encryptedData,
string symmetricAlgorithmUri)
Retrieves the decryption initialization vector (IV) from an <see cref="T:System.Security.Cryptography.Xml.EncryptedData" /> object.
Returns A byte array that contains the decryption initialization vector (IV).
encryptedData
The <see cref="T:System.Security.Cryptography.Xml.EncryptedData" /> object that contains the initialization vector (IV) to retrieve.
symmetricAlgorithmUri
The Uniform Resource Identifier (URI) that describes the cryptographic algorithm associated with the <paramref name="encryptedData" /> value.
public
SymmetricAlgorithm
GetDecryptionKey​(EncryptedData encryptedData,
string symmetricAlgorithmUri)
Retrieves the decryption key from the specified <see cref="T:System.Security.Cryptography.Xml.EncryptedData" /> object.
Returns A <see cref="T:System.Security.Cryptography.SymmetricAlgorithm" /> object associated with the decryption key.
encryptedData
The <see cref="T:System.Security.Cryptography.Xml.EncryptedData" /> object that contains the decryption key to retrieve.
symmetricAlgorithmUri
The size of the decryption key to retrieve.
GetIdElement​(Xml.​XmlDocument document,
string idValue)
Determines how to resolve internal Uniform Resource Identifier (URI) references.
Returns An <see cref="T:System.Xml.XmlElement" /> object that contains an ID indicating how internal Uniform Resource Identifiers (URIs) are to be resolved.
document
An <see cref="T:System.Xml.XmlDocument" /> object that contains an element with an ID value.
idValue
A string that represents the ID value.
public
void
ReplaceData​(Xml.​XmlElement inputElement,
byte[] decryptedData)
Replaces an <see langword="<EncryptedData>" /> element with a specified decrypted sequence of bytes.
inputElement
The <see langword="<EncryptedData>" /> element to replace.
decryptedData
The decrypted data to replace <paramref name="inputElement" /> with.
public static
void
ReplaceElement​(Xml.​XmlElement inputElement,
EncryptedData encryptedData,
bool content)
Replaces the specified element with the specified <see cref="T:System.Security.Cryptography.Xml.EncryptedData" /> object.
inputElement
The element to replace with an <see langword="<EncryptedData>" /> element.
encryptedData
The <see cref="T:System.Security.Cryptography.Xml.EncryptedData" /> object to replace the <paramref name="inputElement" /> parameter with.
content
<see langword="true" /> to replace only the contents of the element; <see langword="false" /> to replace the entire element.
public
bool
Equals​(object obj)
Inherited from object
protected
void
Finalize​()
Inherited from object
public
int
GetHashCode​()
Inherited from object
protected
object
MemberwiseClone​()
Inherited from object
public
string
ToString​()
Inherited from object