Class XmlEncryption
Supports XML encryption.
Implements
Inherited Members
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 |
---|---|---|
ILoggerFactory | loggerFactory | The logger factory. |
IEnumerable<IXmlKeyEncryptionExtension> | xmlKeyEncryptionExtensions | The XML key encryption extensions. |
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 |
---|---|---|
string | dataEncryptionAlgorithm | The data encryption algorithm. |
Returns
Type | Description |
---|---|
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 |
---|---|---|
XmlElement | encryptedElement | The encrypted XML. |
IEnumerable<XmlElement> | encryptedKeyElements | The encrypted keys XML or |
AsymmetricAlgorithm | keyDecryptingKey | The asymmetric key decrypting key. |
string | keyEncryptionAlgorithm | The key encryption algorithm or |
string | dataEncryptionAlgorithm | The data encryption algorithm or |
Returns
Type | Description |
---|---|
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 |
---|---|---|
EncryptedData | encryptedData | The encrypted XML data. |
byte[] | symmetricKey | The symmetric key. |
string | dataEncryptionAlgorithm | The data encryption algorithm. |
Returns
Type | Description |
---|---|
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 |
---|---|---|
EncryptedKey | encryptedKey | The encrypted symmetric key. |
AsymmetricAlgorithm | keyDecryptingKey | The asymmetric key decrypting key. |
string | keyEncryptionAlgorithm | The key encryption algorithm. |
Returns
Type | Description |
---|---|
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 |
---|---|---|
XmlElement | plainTextElement | The plaintext XML. |
AsymmetricAlgorithm | keyEncryptingKey | The asymmetric key encrypting key. |
string | keyEncryptionAlgorithm | The key encryption algorithm. |
string | dataEncryptionAlgorithm | The data encryption algorithm. |
X509Certificate2 | x509Certificate | The X.509 certificate to include in the encrypted data or |
string | digestMethod | The digest method or |
string | maskGenerationFunction | The mask generation function or |
Returns
Type | Description |
---|---|
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 |
---|---|---|
byte[] | plainText | The plaintext. |
byte[] | symmetricKey | The symmetric key. |
string | dataEncryptionAlgorithm | The data encryption algorithm. |
Returns
Type | Description |
---|---|
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 |
---|---|---|
byte[] | symmetricKey | The symmetric key. |
AsymmetricAlgorithm | keyEncryptingKey | The asymmetric key encrypting key. |
string | keyEncryptionAlgorithm | The key encryption algorithm. |
string | digestMethod | The digest method. |
string | maskGenerationFunction | The mask generation function. |
Returns
Type | Description |
---|---|
byte[] | The encrypted symmetric key. |