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
loggerFactoryILoggerFactoryThe logger factory.
xmlKeyEncryptionExtensionsIEnumerable<IXmlKeyEncryptionExtension>The XML key encryption extensions.
xmlDataEncryptionExtensionsIEnumerable<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
dataEncryptionAlgorithmstringThe 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
encryptedElementXmlElementThe encrypted XML.
encryptedKeyElementsIEnumerable<XmlElement>The encrypted keys XML or
nullif included in the encrypted data.keyDecryptingKeyAsymmetricAlgorithmThe asymmetric key decrypting key.
keyEncryptionAlgorithmstringThe key encryption algorithm or
nullif specified in the encrypted key.dataEncryptionAlgorithmstringThe data encryption algorithm or
nullif 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
encryptedDataEncryptedDataThe encrypted XML data.
symmetricKeybyte[]The symmetric key.
dataEncryptionAlgorithmstringThe 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
encryptedKeyEncryptedKeyThe encrypted symmetric key.
keyDecryptingKeyAsymmetricAlgorithmThe asymmetric key decrypting key.
keyEncryptionAlgorithmstringThe 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
plainTextElementXmlElementThe plaintext XML.
keyEncryptingKeyAsymmetricAlgorithmThe asymmetric key encrypting key.
keyEncryptionAlgorithmstringThe key encryption algorithm.
dataEncryptionAlgorithmstringThe data encryption algorithm.
x509CertificateX509Certificate2The X.509 certificate to include in the encrypted data or
nullif none.digestMethodstringThe digest method or
nullif none.maskGenerationFunctionstringThe mask generation function or
nullif 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
plainTextbyte[]The plaintext.
symmetricKeybyte[]The symmetric key.
dataEncryptionAlgorithmstringThe 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
symmetricKeybyte[]The symmetric key.
keyEncryptingKeyAsymmetricAlgorithmThe asymmetric key encrypting key.
keyEncryptionAlgorithmstringThe key encryption algorithm.
digestMethodstringThe digest method.
maskGenerationFunctionstringThe mask generation function.
Returns
- byte[]
The encrypted symmetric key.