Exemplo n.º 1
0
        public override void LoadFrom(string path)
        {
            if (File.Exists(path))
            {
                try
                {
                    byte[] file = RijndaelSimple.DecryptFile(File.ReadAllBytes(path), password, saltValue, AesHashType.MD5.ToString(), passwordIterations, initVector, (int)AesKeySize.Size128);

                    try
                    {
                        using (MemoryStream ms = new MemoryStream(file))
                        {
                            XmlTextReader xr = new XmlTextReader(ms);
                            XmlSerializer xs = new XmlSerializer(this.GetType());
                            object        c;
                            if (xs.CanDeserialize(xr))
                            {
                                c = xs.Deserialize(xr);
                                Type           t          = this.GetType();
                                PropertyInfo[] properties = t.GetProperties();
                                foreach (PropertyInfo p in properties)
                                {
                                    p.SetValue(this, p.GetValue(c, null), null);
                                }
                                Encode(c);
                            }

                            xr.Close();
                            ms.Close();
                        }
                    }
                    catch
                    {
                        throw;
                    }
                }
                catch
                {
                    throw new System.Security.Cryptography.CryptographicException("Could not decrypt file!");
                }
            }
            else
            {
                throw new FileNotFoundException();
            }
        }