Table of Contents

Class XmlEncryption

Namespace
ComponentSpace.Saml2.XmlSecurity.Encryption
Assembly
ComponentSpace.Saml2.dll

Supports XML encryption.

public class XmlEncryption : IXmlEncryption
Inheritance
XmlEncryption
Implements
Inherited Members

Constructors

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

Initializes a new instance of the XmlEncryption class.

public XmlEncryption(ILoggerFactory loggerFactory, IEnumerable<IXmlKeyEncryptionExtension> xmlKeyEncryptionExtensions, IEnumerable<IXmlDataEncryptionExtension> xmlDataEncryptionExtensions)

Parameters

loggerFactory ILoggerFactory

The logger factory.

xmlKeyEncryptionExtensions IEnumerable<IXmlKeyEncryptionExtension>

The XML key encryption extensions.

xmlDataEncryptionExtensions IEnumerable<IXmlDataEncryptionExtension>

The XML data encryption extensions.

Methods

CreateSymmetricKey(string)

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

protected virtual byte[] CreateSymmetricKey(string dataEncryptionAlgorithm)

Parameters

dataEncryptionAlgorithm string

The data encryption algorithm.

Returns

byte[]

The symmetric key.

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

Decrypts the XML.

public virtual XmlElement Decrypt(XmlElement encryptedElement, IEnumerable<XmlElement> encryptedKeyElements, AsymmetricAlgorithm keyDecryptingKey, string keyEncryptionAlgorithm = null, string dataEncryptionAlgorithm = null)

Parameters

encryptedElement XmlElement

The encrypted XML.

encryptedKeyElements IEnumerable<XmlElement>

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

keyDecryptingKey AsymmetricAlgorithm

The asymmetric key decrypting key.

keyEncryptionAlgorithm string

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

dataEncryptionAlgorithm string

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

Returns

XmlElement

The plaintext XML.

Exceptions

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.

protected virtual byte[] DecryptData(EncryptedData encryptedData, byte[] symmetricKey, string dataEncryptionAlgorithm)

Parameters

encryptedData EncryptedData

The encrypted XML data.

symmetricKey byte[]

The symmetric key.

dataEncryptionAlgorithm string

The data encryption algorithm.

Returns

byte[]

The decrypted XML element.

DecryptSymmetricKey(EncryptedKey, AsymmetricAlgorithm, string)

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

protected virtual byte[] DecryptSymmetricKey(EncryptedKey encryptedKey, AsymmetricAlgorithm keyDecryptingKey, string keyEncryptionAlgorithm)

Parameters

encryptedKey EncryptedKey

The encrypted symmetric key.

keyDecryptingKey AsymmetricAlgorithm

The asymmetric key decrypting key.

keyEncryptionAlgorithm string

The key encryption algorithm.

Returns

byte[]

The decrypted symmetric key.

Encrypt(XmlElement, AsymmetricAlgorithm, string, string, X509Certificate2, string, string)

Encrypts the XML.

public virtual XmlElement Encrypt(XmlElement plainTextElement, AsymmetricAlgorithm keyEncryptingKey, string keyEncryptionAlgorithm, string dataEncryptionAlgorithm, X509Certificate2 x509Certificate = null, string digestMethod = null, string maskGenerationFunction = null)

Parameters

plainTextElement XmlElement

The plaintext XML.

keyEncryptingKey AsymmetricAlgorithm

The asymmetric key encrypting key.

keyEncryptionAlgorithm string

The key encryption algorithm.

dataEncryptionAlgorithm string

The data encryption algorithm.

x509Certificate X509Certificate2

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

digestMethod string

The digest method or null if none.

maskGenerationFunction string

The mask generation function or null if none.

Returns

XmlElement

The encrypted XML.

Exceptions

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.

protected virtual byte[] EncryptData(byte[] plainText, byte[] symmetricKey, string dataEncryptionAlgorithm)

Parameters

plainText byte[]

The plaintext.

symmetricKey byte[]

The symmetric key.

dataEncryptionAlgorithm string

The data encryption algorithm.

Returns

byte[]

The encrypted XML element.

EncryptSymmetricKey(byte[], AsymmetricAlgorithm, string, string, string)

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

protected virtual byte[] EncryptSymmetricKey(byte[] symmetricKey, AsymmetricAlgorithm keyEncryptingKey, string keyEncryptionAlgorithm, string digestMethod, string maskGenerationFunction)

Parameters

symmetricKey byte[]

The symmetric key.

keyEncryptingKey AsymmetricAlgorithm

The asymmetric key encrypting key.

keyEncryptionAlgorithm string

The key encryption algorithm.

digestMethod string

The digest method.

maskGenerationFunction string

The mask generation function.

Returns

byte[]

The encrypted symmetric key.