/// <summary>
 /// Creates a security token easily adopted into various services in the format of the <see cref="SecurityToken.ToString()"/> method.
 /// The token itself is encrypted using the <see cref="AdvancedEncryptionStandardUtility.Encrypt"/> method.
 /// </summary>
 /// <param name="token">The <see cref="SecurityToken"/> to convert and encrypt to a byte[] representation.</param>
 /// <param name="securityKey">The key to use in the encryption algorithm.</param>
 /// <param name="securityInitializationVector">The initialization vector (IV) to use in the encryption algorithm.</param>
 /// <returns>A security token easily adopted into various services in the format of the <see cref="SecurityToken.ToString()"/> method.</returns>
 public static byte[] CreateEncryptedSecurityToken(SecurityToken token, byte[] securityKey, byte[] securityInitializationVector)
 {
     if (token == null)
     {
         throw new ArgumentNullException(nameof(token));
     }
     byte[] securityToken = AdvancedEncryptionStandardUtility.Encrypt(ByteConverter.FromString(token.ToString(), options =>
     {
         options.Encoding = Encoding.UTF8;
         options.Preamble = PreambleSequence.Remove;
     }), securityKey, securityInitializationVector);
     return(securityToken);
 }
        /// <summary>
        /// Creates and returns a mappable XML document of the original values and the obfuscated values.
        /// </summary>
        /// <returns>A mappable XML document of the original values and the obfuscated values.</returns>
        public override Stream CreateMapping()
        {
            MemoryStream output;
            MemoryStream tempOutput = null;

            try
            {
                XmlDocument document                   = XmlDocumentConverter.FromStream(base.CreateMapping());
                XmlNode     mappingNode                = document.DocumentElement;
                string      innerXmlOfMappingNode      = mappingNode.InnerXml;
                byte[]      innerXmlOfMappingNodeBytes = ByteConverter.FromString(innerXmlOfMappingNode, options =>
                {
                    options.Encoding = Encoding;
                    options.Preamble = PreambleSequence.Remove;
                });
                XmlElement encryptedNode = document.CreateElement(MappingEncryptedElement);
                encryptedNode.InnerText = Convert.ToBase64String(AdvancedEncryptionStandardUtility.Encrypt(innerXmlOfMappingNodeBytes, Key, InitializationVector));
                mappingNode.InnerXml    = "";
                mappingNode.AppendChild(encryptedNode);
                tempOutput = new MemoryStream();
                using (XmlWriter writer = XmlWriter.Create(tempOutput, XmlWriterUtility.CreateSettings(o => o.Encoding = Encoding)))
                {
                    document.WriteTo(writer);
                }
                tempOutput.Position = 0;
                output     = tempOutput;
                tempOutput = null;
            }
            finally
            {
                if (tempOutput != null)
                {
                    tempOutput.Dispose();
                }
            }
            return(output);
        }