/// <summary>
 /// Decrypt method implementation
 /// </summary>
 public override byte[] Decrypt(byte[] data, string description = "")
 {
     try
     {
         byte[] Hdr = GetHeader(data);
         if (Hdr.SequenceEqual(new byte[] { 0x17, 0xD3, 0xF4, 0x2B }))  // RSA
         {
             using (RSASystemEncryption enc = new RSASystemEncryption())
             {
                 return(enc.Decrypt(data));
             }
         }
         else if (Hdr.SequenceEqual(new byte[] { 0x17, 0xD3, 0xF4, 0x2A }))  // AES256
         {
             using (AESSystemEncryption enc = new AESSystemEncryption())
             {
                 return(enc.Decrypt(data));
             }
         }
         else
         {
             return(data);
         }
     }
     catch
     {
         return(data);
     }
 }
Example #2
0
        /// <summary>
        /// GetCryptedConfig method implementation
        /// </summary>
        private static byte[] GetCryptedConfig(MFAConfig config)
        {
            using (AESSystemEncryption MSIS = new AESSystemEncryption())
            {
                config.KeysConfig.XORSecret = MSIS.Encrypt(config.KeysConfig.XORSecret);
                config.Hosts.ActiveDirectoryHost.Password = MSIS.Encrypt(config.Hosts.ActiveDirectoryHost.Password);
                config.Hosts.SQLServerHost.SQLPassword    = MSIS.Decrypt(config.Hosts.SQLServerHost.SQLPassword);
                config.MailProvider.Password = MSIS.Encrypt(config.MailProvider.Password);
            };
            XmlConfigSerializer xmlserializer = new XmlConfigSerializer(typeof(MFAConfig));
            MemoryStream        stm           = new MemoryStream();

            using (StreamReader reader = new StreamReader(stm))
            {
                xmlserializer.Serialize(stm, config);
                stm.Position = 0;
                byte[] bytes = null;
                using (AESSystemEncryption aes = new AESSystemEncryption())
                {
                    bytes = aes.Encrypt(stm.ToArray());
                }
                return(bytes);
            }
        }