示例#1
0
        public static byte[] Encrypt(byte[] data)
        {
            byte[] response = null;

            if (util.IsValidXML((data)).Equals(false))
            {
                MessageBox.Show("Not a valid config file...", "Confirmation", MessageBoxButton.OK, MessageBoxImage.Error);
                return(null);
            }

            byte[] clearText = data;

            try
            {
                byte[] comp = Zlib.CompressData(clearText);

                response = AESHelper(KEY[0], IV[0], comp);                 // use v2 key, v3 can read configs that are encrypted with the v2 key
            }
            catch (Exception ex)
            {
                LogManager.WriteToLog(ex.ToString());
                MessageBox.Show("unable to encrypt config file", "Confirmation", MessageBoxButton.OK, MessageBoxImage.Error);
                return(null);
            }

            return(response);
        }
示例#2
0
        public static byte[] Decrypt(byte[] clearText)
        {
            byte[] response = new byte[0];

            byte[] data;
            for (int x = 0; x < KEY.Length; x++)
            {
                try
                {
                    byte[] key = KEY[x];
                    byte[] iv  = IV[x];
                    data = AESHelper(key, iv, clearText, true);
                    var d = Zlib.DecompressData(data);
                    Array.Resize(ref response, d.Length);
                    Array.Copy(d, response, d.Length);
                }
                catch (Exception)
                {
                    continue;
                }

                break;
            }

            if (response.Length == 0)
            {
                MessageBox.Show("unable to decrypt config file", "Confirmation", MessageBoxButton.OK, MessageBoxImage.Error);
                return(null);
            }


            if (util.IsValidXML(response).Equals(false))
            {
                MessageBox.Show("Not a valid config file...", "Confirmation", MessageBoxButton.OK, MessageBoxImage.Error);
                return(null);
            }

            return(response);
        }