Ejemplo n.º 1
0
        public ContainerStatus Save(string fileName)
        {
            Logger.Debug("Saving as : " + fileName);
            if (IsEmpty())
            {
                Logger.Warn("No files added cannot save as : " + fileName);
                return(ContainerStatus.Empty);
            }

            if (Template == null || Template.Length != TemplateOperations.TemplateLength)
            {
                Logger.Warn("Template is null cannot save as : " + fileName);
                return(ContainerStatus.NullTemplate);
            }
            byte[] fileStmWithTempAndFile;
            if (!AddPassword)
            {
                TemplateOperations = new NLockTemplateOperationsAes();
                if (!IsLocked)
                {
                    Lock();
                    fileStmWithTempAndFile = TemplateOperations.GenerateNLockFileContent(Template, _lockedContent);
                }
                else
                {
                    fileStmWithTempAndFile = TemplateOperations.GenerateNLockFileContent(Template, _lockedContent);
                }
            }
            else
            {
                TemplateOperations = new NLockTemplateOperationsCommon();
                if (!IsLocked)
                {
                    Lock();
                    fileStmWithTempAndFile = TemplateOperations.GenerateNLockFileContent(Template, _lockedContent,
                                                                                         Password);
                }
                else
                {
                    fileStmWithTempAndFile = TemplateOperations.GenerateNLockFileContent(Template, _lockedContent,
                                                                                         Password);
                }
            }

            if (File.Exists(fileName))
            {
                Logger.Debug(fileName + " already exists so deleting");
                File.Delete(fileName);
            }

            using (var fs2 = File.Create(fileName))
            {
                Logger.Debug(fileName + " is being written");
                fs2.Write(fileStmWithTempAndFile, 0, fileStmWithTempAndFile.Length);
                fs2.Close();
            }
            _container.Dispose();
            return(ContainerStatus.Ok);
        }
Ejemplo n.º 2
0
        private int DecideTemplateOperations(string fileName)
        {
            var type = NLockTemplateOperations.IsNLock(fileName);

            Logger.Debug("DecideTemplateOperations Type : " + type);
            switch (type)
            {
            case 1:
                TemplateOperations = new NLockTemplateOperationsAes();
                break;

            case 2:
                TemplateOperations = new NLockTemplateOperationsCommon();
                break;

            default:
                Logger.Error("Invalid NLock file type");
                break;
            }
            return(type);
        }
Ejemplo n.º 3
0
        private void VerifyWithPassword()
        {
            lblInfo.Text = Resources.Verifying_using_password____;
            Verified     = false;
            if (tbPw.Text != null && PwHash != null)
            {
                if (NLockTemplateOperationsCommon.ValidatePassword(NLockTemplateOperations.GetBytes(tbPw.Text), PwHash))
                {
                    Verified     = true;
                    DialogResult = DialogResult.OK;
                }
                else
                {
                    lblInfo.Text = Resources.Invalid_password___;
                    _currentop   = Ops.Verificationfailedretry;
                    EnableRetryCounter();
                }
            }
            else if (PwHash == null)
            {
                lblHelpText.Text        = Resources.Password_not_supported;
                lblInfo.Text            = Resources.Failed___;
                llblRetryWithPW.Enabled = false;
                llblRetryWithPW.Visible = false;
                tbPw.Enabled            = false;
                tbPw.Visible            = false;

                _retryWithPw = false;
                _currentop   = Ops.Passwordnotsupported;
            }
            else
            {
                lblInfo.Text = Resources.Invalid_password___;
                _currentop   = Ops.Verificationfailedretry;
            }
        }