Esempio n. 1
0
        public void LoadFromFile(string fileName)
        {
            IsLocked = true;
            FileName = fileName;
            var full = File.ReadAllBytes(fileName);
            var type = DecideTemplateOperations(fileName);

            if (type > 0)
            {
                Logger.Debug("LoadFromFile Type : " + type);

                var zipContent = TemplateOperations.ExtractDataContentFromNLock(full);
                try
                {
                    Template = TemplateOperations.ExtractTemplateFromNLock(full);
                    Template = _encryptionStrategy.Decrypt(zipContent, Template);
                }
                catch (Exception)
                {
                    throw;
                }

                UnlockForm loginFrom;

                if (type == 2)
                {
                    var hash = TemplateOperations.GetHashFromNLock(full);
                    Logger.Debug("LoadFromFile Hash : " + Encoding.UTF8.GetString(hash));
                    loginFrom = new UnlockForm(Template, hash, fileName);
                }
                else
                {
                    loginFrom = new UnlockForm(Template, fileName)
                    {
                        PwHash = null
                    };
                }
                loginFrom.ShowDialog();
                var result = loginFrom.DialogResult;
                if (result != DialogResult.Cancel)
                {
                    _verified = loginFrom.Verified;
                    if (Unlock() == VerificationStatus.Failed)
                    {
                        throw new Exception("Loading from file failed");
                    }
                }
                loginFrom.Dispose();
            }
            else
            {
                throw new Exception("Loading from file failed");
            }
        }
Esempio n. 2
0
 private VerificationStatus Unlock()
 {
     Logger.Debug("Unlocking");
     if (_verified)
     {
         if (FileName != null)
         {
             var zipContent = TemplateOperations.ExtractDataContentFromNLock(FileName);
             Logger.Debug("ExtractDataContentFromNLock");
             _lockedContent = _encryptionStrategy.Decrypt(Template, zipContent);
             _container.LoadFromMemory(_lockedContent);
             IsLocked = false;
         }
         return(VerificationStatus.Verfified);
     }
     else
     {
         Logger.Debug("Not verified");
         IsLocked = true;
         return(VerificationStatus.Failed);
     }
 }