Show / Hide Table of Contents

Class XmlEncryption

Supports XML encryption.

Inheritance
System.Object
XmlEncryption
Implements
IXmlEncryption
Inherited Members
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.ToString()
Namespace: ComponentSpace.Saml2.XmlSecurity.Encryption
Assembly: ComponentSpace.Saml2.dll
Syntax
public class XmlEncryption : IXmlEncryption

Constructors

XmlEncryption(ILoggerFactory, IEnumerable<IXmlKeyEncryptionExtension>, IEnumerable<IXmlDataEncryptionExtension>)

Initializes a new instance of the XmlEncryption class.

Declaration
public XmlEncryption(ILoggerFactory loggerFactory, IEnumerable<IXmlKeyEncryptionExtension> xmlKeyEncryptionExtensions, IEnumerable<IXmlDataEncryptionExtension> xmlDataEncryptionExtensions)
Parameters
Type Name Description
Microsoft.Extensions.Logging.ILoggerFactory loggerFactory

The logger factory.

System.Collections.Generic.IEnumerable<IXmlKeyEncryptionExtension> xmlKeyEncryptionExtensions

The XML key encryption extensions.

System.Collections.Generic.IEnumerable<IXmlDataEncryptionExtension> xmlDataEncryptionExtensions

The XML data encryption extensions.

Methods

CreateSymmetricKey(String)

Creates a random symmetric key supporting the specified data encryption algorithm.

Declaration
protected virtual byte[] CreateSymmetricKey(string dataEncryptionAlgorithm)
Parameters
Type Name Description
System.String dataEncryptionAlgorithm

The data encryption algorithm.

Returns
Type Description
System.Byte[]

The symmetric key.

Decrypt(XmlElement, IEnumerable<XmlElement>, AsymmetricAlgorithm, String, String)

Decrypts the XML.

Declaration
public virtual XmlElement Decrypt(XmlElement encryptedElement, IEnumerable<XmlElement> encryptedKeyElements, AsymmetricAlgorithm keyDecryptingKey, string keyEncryptionAlgorithm = null, string dataEncryptionAlgorithm = null)
Parameters
Type Name Description
System.Xml.XmlElement encryptedElement

The encrypted XML.

System.Collections.Generic.IEnumerable<System.Xml.XmlElement> encryptedKeyElements

The encrypted keys XML or null if included in the encrypted data.

System.Security.Cryptography.AsymmetricAlgorithm keyDecryptingKey

The asymmetric key decrypting key.

System.String keyEncryptionAlgorithm

The key encryption algorithm or null if specified in the encrypted key.

System.String dataEncryptionAlgorithm

The data encryption algorithm or null if specified in the encrypted data.

Returns
Type Description
System.Xml.XmlElement

The plaintext XML.

Exceptions
Type Condition
SamlEncryptionException

Thrown if an error occurs during decryption.

DecryptData(EncryptedData, Byte[], String)

Decrypts the encrypted XML data using the specified symmetric key and data encryption algorithm.

Declaration
protected virtual byte[] DecryptData(EncryptedData encryptedData, byte[] symmetricKey, string dataEncryptionAlgorithm)
Parameters
Type Name Description
System.Security.Cryptography.Xml.EncryptedData encryptedData

The encrypted XML data.

System.Byte[] symmetricKey

The symmetric key.

System.String dataEncryptionAlgorithm

The data encryption algorithm.

Returns
Type Description
System.Byte[]

The decrypted XML element.

DecryptSymmetricKey(EncryptedKey, AsymmetricAlgorithm, String)

Decrypts the symmetric key using the specified asymmetric key and key encryption algorithm

Declaration
protected virtual byte[] DecryptSymmetricKey(EncryptedKey encryptedKey, AsymmetricAlgorithm keyDecryptingKey, string keyEncryptionAlgorithm)
Parameters
Type Name Description
System.Security.Cryptography.Xml.EncryptedKey encryptedKey

The encrypted symmetric key.

System.Security.Cryptography.AsymmetricAlgorithm keyDecryptingKey

The asymmetric key decrypting key.

System.String keyEncryptionAlgorithm

The key encryption algorithm.

Returns
Type Description
System.Byte[]

The decrypted symmetric key.

Encrypt(XmlElement, AsymmetricAlgorithm, String, String, X509Certificate2, String, String)

Encrypts the XML.

Declaration
public virtual XmlElement Encrypt(XmlElement plainTextElement, AsymmetricAlgorithm keyEncryptingKey, string keyEncryptionAlgorithm, string dataEncryptionAlgorithm, X509Certificate2 x509Certificate = null, string digestMethod = null, string maskGenerationFunction = null)
Parameters
Type Name Description
System.Xml.XmlElement plainTextElement

The plaintext XML.

System.Security.Cryptography.AsymmetricAlgorithm keyEncryptingKey

The asymmetric key encrypting key.

System.String keyEncryptionAlgorithm

The key encryption algorithm.

System.String dataEncryptionAlgorithm

The data encryption algorithm.

System.Security.Cryptography.X509Certificates.X509Certificate2 x509Certificate

The X.509 certificate to include in the encrypted data or null if none.

System.String digestMethod

The digest method or null if none.

System.String maskGenerationFunction

The mask generation function or null if none.

Returns
Type Description
System.Xml.XmlElement

The encrypted XML.

Exceptions
Type Condition
SamlEncryptionException

Thrown if an error occurs during encryption.

EncryptData(Byte[], Byte[], String)

Encrypts the XML element using the specified symmetric key and data encryption algorithm.

Declaration
protected virtual byte[] EncryptData(byte[] plainText, byte[] symmetricKey, string dataEncryptionAlgorithm)
Parameters
Type Name Description
System.Byte[] plainText

The plaintext.

System.Byte[] symmetricKey

The symmetric key.

System.String dataEncryptionAlgorithm

The data encryption algorithm.

Returns
Type Description
System.Byte[]

The encrypted XML element.

EncryptSymmetricKey(Byte[], AsymmetricAlgorithm, String, String, String)

Encrypts the symmetric key using the specified asymmetric key and key encryption algorithm.

Declaration
protected virtual byte[] EncryptSymmetricKey(byte[] symmetricKey, AsymmetricAlgorithm keyEncryptingKey, string keyEncryptionAlgorithm, string digestMethod, string maskGenerationFunction)
Parameters
Type Name Description
System.Byte[] symmetricKey

The symmetric key.

System.Security.Cryptography.AsymmetricAlgorithm keyEncryptingKey

The asymmetric key encrypting key.

System.String keyEncryptionAlgorithm

The key encryption algorithm.

System.String digestMethod

The digest method.

System.String maskGenerationFunction

The mask generation function.

Returns
Type Description
System.Byte[]

The encrypted symmetric key.

Implements

IXmlEncryption
In This Article
Back to top Copyright © ComponentSpace Pty Ltd 2017-2022. All rights reserved.