コード例 #1
0
ファイル: DocumentWriter.cs プロジェクト: huangt5/MyTools
        public void Write()
        {
            SecurityCenterDocument doc = _state.Doc;

            doc.DefaultGroup  = ClearState.ConvertNoteGroup(_state.ClearGroup, _state.Password, false);
            doc.LastUpdated   = DateTime.Now;
            doc.Schema        = Schema.CurrentSchema;
            doc.Security      = new Security();
            doc.Security.Hash = CryptoFactory.Instance.GetPwdHashService().Encrypt(_state.Password, "");

            using (FileStream fs = new FileStream(Environment.CurrentDirectory + "\\Security.dat", FileMode.Create)) {
                XmlSerializer xs = new XmlSerializer(typeof(SecurityCenterDocument));
                xs.Serialize(fs, doc);
            }
        }
コード例 #2
0
ファイル: DocumentReader.cs プロジェクト: huangt5/MyTools
        public void LoadFromFile(string file)
        {
            SecurityCenterDocument doc;

            using (FileStream fs = new FileStream(file, FileMode.Open)) {
                XmlSerializer ser = new XmlSerializer(typeof(SecurityCenterDocument));
                doc = (SecurityCenterDocument)ser.Deserialize(fs);
            }

            ICryptoService hashService = CryptoFactory.Instance.GetPwdHashService();

            if (hashService.Encrypt(_pwd, "") != doc.Security.Hash)
            {
                throw new WrongPasswordException();
            }

            _state                 = new ClearState();
            _state.Doc             = doc;
            _state.Password        = _pwd;
            _state.ClearGroup      = ClearState.ConvertNoteGroup(doc.DefaultGroup, _pwd, true);
            _state.ClearGroup.Name = "<default>";
        }