当前位置: 首页>>代码示例>>C#>>正文


C# CompositeKey.AddUserKey方法代码示例

本文整理汇总了C#中KeePassLib.Keys.CompositeKey.AddUserKey方法的典型用法代码示例。如果您正苦于以下问题:C# CompositeKey.AddUserKey方法的具体用法?C# CompositeKey.AddUserKey怎么用?C# CompositeKey.AddUserKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在KeePassLib.Keys.CompositeKey的用法示例。


在下文中一共展示了CompositeKey.AddUserKey方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

    public static void Main(string[] args)
    {
        CompositeKey key = new CompositeKey();
        KcpPassword pw = new KcpPassword("12345");
        key.AddUserKey(pw);
        byte[] pwdata = pw.KeyData.ReadData();
        Console.WriteLine("PW data:");
        Console.WriteLine(string.Join(",", pwdata.Select(x => "0x" + x.ToString("x"))));
        byte[] keydata = key.GenerateKey32(pwdata, 6000).ReadData();
        Console.WriteLine("Key data:");
        Console.WriteLine(string.Join(",", keydata.Select(x => "0x" + x.ToString("x"))));

        PwDatabase db = new PwDatabase();
        db.MasterKey = key;
        KdbxFile kdbx = new KdbxFile(db);
        kdbx.Load(@"..\resources\test.kdbx", KdbxFormat.Default, null);

        var groups = db.RootGroup.GetGroups(true);
        Console.WriteLine("Group count: " + groups.UCount);
        var entries = db.RootGroup.GetEntries(true);
        Console.WriteLine("Entry count: " + entries.UCount);

        CompositeKey key2 = new CompositeKey();
        key2.AddUserKey(pw);
        KcpKeyFile keyfile = new KcpKeyFile(@"..\resources\keyfile.key");
        key2.AddUserKey(keyfile);
        byte[] keyfiledata = keyfile.KeyData.ReadData();
        Console.WriteLine("Key file data:");
        Console.WriteLine(string.Join(",", keyfiledata.Select(x => "0x" + x.ToString("x"))));
        Console.WriteLine("Composite Key data:");
        byte[] key2data = key2.GenerateKey32(keyfiledata, 6000).ReadData();
        Console.WriteLine(string.Join(",", key2data.Select(x => "0x" + x.ToString("x"))));
    }
开发者ID:jdonofrio728,项目名称:keepassj,代码行数:33,代码来源:test.cs

示例2: KeyFromCommandLine

        public static CompositeKey KeyFromCommandLine(CommandLineArgs args)
        {
            if(args == null) throw new ArgumentNullException("args");

            CompositeKey cmpKey = new CompositeKey();
            string strPassword = args[AppDefs.CommandLineOptions.Password];
            string strKeyFile = args[AppDefs.CommandLineOptions.KeyFile];
            string strUserAcc = args[AppDefs.CommandLineOptions.UserAccount];

            if(strPassword != null)
                cmpKey.AddUserKey(new KcpPassword(strPassword));

            if(strKeyFile != null)
            {
                try { cmpKey.AddUserKey(new KcpKeyFile(strKeyFile)); }
                catch(Exception exKey)
                {
                    MessageService.ShowWarning(strKeyFile, KPRes.KeyFileError, exKey);
                    return null;
                }
            }

            if(strUserAcc != null)
            {
                try { cmpKey.AddUserKey(new KcpUserAccount()); }
                catch(Exception exUA)
                {
                    MessageService.ShowWarning(exUA);
                    return null;
                }
            }

            return ((cmpKey.UserKeyCount > 0) ? cmpKey : null);
        }
开发者ID:jonbws,项目名称:strengthreport,代码行数:34,代码来源:KeyUtil.cs

示例3: CreateKey

 protected static CompositeKey CreateKey(string password, string keyfile)
 {
     CompositeKey key = new CompositeKey();
     key.AddUserKey(new KcpPassword(password));
     if (!String.IsNullOrEmpty(keyfile))
         key.AddUserKey(new KcpKeyFile(keyfile));
     return key;
 }
开发者ID:pythe,项目名称:wristpass,代码行数:8,代码来源:TestBase.cs

示例4: CreateCompositeKey

        public static CompositeKey CreateCompositeKey(string keyPassword = null, string keyFile = null, bool userAccount = false)
        {
            var emptyPassword = string.IsNullOrWhiteSpace(keyPassword);
            var emptyKeyFile = string.IsNullOrWhiteSpace(keyFile);

            if(emptyPassword && emptyKeyFile && !userAccount)
                throw new ArgumentException("KeyPass requires at least one form of authentication: Password, KeyFile, or UserAccount");

            var key = new CompositeKey();

            if (!emptyPassword)
                key.AddUserKey(new KcpPassword(keyPassword));

            if (!emptyKeyFile)
                key.AddUserKey(new KcpKeyFile(keyFile));

            if (userAccount)
                key.AddUserKey(new KcpUserAccount());

            return key;
        }
开发者ID:badmishkallc,项目名称:jolt9-devops,代码行数:21,代码来源:Util.cs

示例5: KeyFromCommandLine

        public static CompositeKey KeyFromCommandLine(CommandLineArgs args)
        {
            if(args == null) throw new ArgumentNullException("args");

            CompositeKey cmpKey = new CompositeKey();
            string strPassword = args[AppDefs.CommandLineOptions.Password];
            string strPasswordEnc = args[AppDefs.CommandLineOptions.PasswordEncrypted];
            string strPasswordStdIn = args[AppDefs.CommandLineOptions.PasswordStdIn];
            string strKeyFile = args[AppDefs.CommandLineOptions.KeyFile];
            string strUserAcc = args[AppDefs.CommandLineOptions.UserAccount];

            if(strPassword != null)
                cmpKey.AddUserKey(new KcpPassword(strPassword));
            else if(strPasswordEnc != null)
                cmpKey.AddUserKey(new KcpPassword(StrUtil.DecryptString(strPasswordEnc)));
            else if(strPasswordStdIn != null)
            {
                KcpPassword kcpPw = ReadPasswordStdIn(true);
                if(kcpPw != null) cmpKey.AddUserKey(kcpPw);
            }

            if(strKeyFile != null)
            {
                if(Program.KeyProviderPool.IsKeyProvider(strKeyFile))
                {
                    KeyProviderQueryContext ctxKP = new KeyProviderQueryContext(
                        IOConnectionInfo.FromPath(args.FileName), false, false);

                    bool bPerformHash;
                    byte[] pbProvKey = Program.KeyProviderPool.GetKey(strKeyFile, ctxKP,
                        out bPerformHash);
                    if((pbProvKey != null) && (pbProvKey.Length > 0))
                    {
                        try { cmpKey.AddUserKey(new KcpCustomKey(strKeyFile, pbProvKey, bPerformHash)); }
                        catch(Exception exCKP)
                        {
                            MessageService.ShowWarning(exCKP);
                            return null;
                        }

                        Array.Clear(pbProvKey, 0, pbProvKey.Length);
                    }
                    else return null; // Provider has shown error message
                }
                else // Key file
                {
                    try { cmpKey.AddUserKey(new KcpKeyFile(strKeyFile)); }
                    catch(Exception exKey)
                    {
                        MessageService.ShowWarning(strKeyFile, KPRes.KeyFileError, exKey);
                        return null;
                    }
                }
            }

            if(strUserAcc != null)
            {
                try { cmpKey.AddUserKey(new KcpUserAccount()); }
                catch(Exception exUA)
                {
                    MessageService.ShowWarning(exUA);
                    return null;
                }
            }

            if(cmpKey.UserKeyCount > 0)
            {
                ClearKeyOptions(args, true);
                return cmpKey;
            }

            return null;
        }
开发者ID:Stoom,项目名称:KeePass,代码行数:73,代码来源:KeyUtil.cs

示例6: CreateKeyFor

 public static CompositeKey CreateKeyFor(string password)
 {
     CompositeKey key = new CompositeKey();
     key.AddUserKey(new KcpPassword(password));
     return key;
 }
开发者ID:hicknhack-software,项目名称:KeeShare,代码行数:6,代码来源:SyncSource.cs

示例7: CreateDatabase

        private void CreateDatabase()
        {
            var keyfileCheckbox = FindViewById<CheckBox>(Resource.Id.use_keyfile);
            string password;
            if (!TryGetPassword(out password)) return;

            // Verify that a password or keyfile is set
            if (password.Length == 0 && !keyfileCheckbox.Checked)
            {
                Toast.MakeText(this, Resource.String.error_nopass, ToastLength.Long).Show();
                return;
            }

            //create the key
            CompositeKey newKey = new CompositeKey();
            if (String.IsNullOrEmpty(password) == false)
            {
                newKey.AddUserKey(new KcpPassword(password));
            }
            if (String.IsNullOrEmpty(_keyfileFilename) == false)
            {
                try
                {
                    newKey.AddUserKey(new KcpKeyFile(_keyfileFilename));
                }
                catch (Exception)
                {
                    Toast.MakeText(this, Resource.String.error_adding_keyfile, ToastLength.Long).Show();
                    return;
                }
            }

            // Create the new database
            CreateDb create = new CreateDb(App.Kp2a, this, _ioc, new LaunchGroupActivity(_ioc, this), false, newKey);
            ProgressTask createTask = new ProgressTask(
                App.Kp2a,
                this, create);
            createTask.Run();
        }
开发者ID:pythe,项目名称:wristpass,代码行数:39,代码来源:CreateDatabaseActivity.cs

示例8: CreateCompositeKey

        private bool CreateCompositeKey()
        {
            m_pKey = new CompositeKey();

            if(m_cbPassword.Checked) // Use a password
            {
                byte[] pb = m_secPassword.ToUtf8();
                m_pKey.AddUserKey(new KcpPassword(pb));
                Array.Clear(pb, 0, pb.Length);
            }

            string strKeyFile = m_cmbKeyFile.Text;
            Debug.Assert(strKeyFile != null); if(strKeyFile == null) strKeyFile = string.Empty;
            bool bIsProvKey = Program.KeyProviderPool.IsKeyProvider(strKeyFile);

            if(m_cbKeyFile.Checked && (!strKeyFile.Equals(KPRes.NoKeyFileSpecifiedMeta)) &&
                (bIsProvKey == false))
            {
                if(ValidateKeyFileLocation() == false)
                {
                    m_pKey = null;
                    return false;
                }

                try { m_pKey.AddUserKey(new KcpKeyFile(strKeyFile)); }
                catch(Exception)
                {
                    MessageService.ShowWarning(strKeyFile, KPRes.KeyFileError);
                    m_pKey = null;
                    return false;
                }
            }
            else if(m_cbKeyFile.Checked && (!strKeyFile.Equals(KPRes.NoKeyFileSpecifiedMeta)) &&
                (bIsProvKey == true))
            {
                byte[] pbProvKey = Program.KeyProviderPool.GetKey(strKeyFile);

                try { m_pKey.AddUserKey(new KcpCustomKey(pbProvKey)); }
                catch(Exception exCKP)
                {
                    MessageService.ShowWarning(strKeyFile, KPRes.KeyFileError, exCKP);
                    m_pKey = null;
                    return false;
                }

                if((pbProvKey != null) && (pbProvKey.Length > 0))
                    Array.Clear(pbProvKey, 0, pbProvKey.Length);
            }

            if(m_cbUserAccount.Checked)
            {
                try { m_pKey.AddUserKey(new KcpUserAccount()); }
                catch(Exception exUA)
                {
                    MessageService.ShowWarning(exUA);
                    return false;
                }
            }

            return true;
        }
开发者ID:jonbws,项目名称:strengthreport,代码行数:61,代码来源:KeyPromptForm.cs

示例9: CreateCompositeKey

        private CompositeKey CreateCompositeKey(string masterKey)
        {
            CompositeKey m_pKey = new CompositeKey ();

             SecureEdit se = new SecureEdit (masterKey);
             byte[] pb = se.ToUtf8 ();
             m_pKey.AddUserKey (new KcpPassword (pb));
             Array.Clear (pb, 0, pb.Length);

             return m_pKey;
        }
开发者ID:enecciari,项目名称:mackeepass,代码行数:11,代码来源:DatabaseCommands.cs

示例10: CreateCompositeKey

        private bool CreateCompositeKey()
        {
            m_pKey = new CompositeKey();

            if(m_cbPassword.Checked) // Use a password
            {
                if(m_cbHidePassword.Checked)
                {
                    if(m_secPassword.ContentsEqualTo(m_secRepeat) == false)
                    {
                        MessageService.ShowWarning(KPRes.PasswordRepeatFailed);
                        return false;
                    }
                }

                uint uMinLen = Program.Config.Security.MasterPassword.MinimumLength;
                if(m_secPassword.TextLength < uMinLen)
                {
                    string strML = KPRes.MasterPasswordMinLengthFailed;
                    strML = strML.Replace(@"{PARAM}", uMinLen.ToString());
                    MessageService.ShowWarning(strML);
                    return false;
                }

                byte[] pb = m_secPassword.ToUtf8();

                uint uMinQual = Program.Config.Security.MasterPassword.MinimumQuality;
                if(QualityEstimation.EstimatePasswordBits(pb) < uMinQual)
                {
                    string strMQ = KPRes.MasterPasswordMinQualityFailed;
                    strMQ = strMQ.Replace(@"{PARAM}", uMinQual.ToString());
                    MessageService.ShowWarning(strMQ);
                    Array.Clear(pb, 0, pb.Length);
                    return false;
                }

                m_pKey.AddUserKey(new KcpPassword(pb));
                Array.Clear(pb, 0, pb.Length);
            }

            string strKeyFile = m_cmbKeyFile.Text;
            bool bIsKeyProv = Program.KeyProviderPool.IsKeyProvider(strKeyFile);

            if(m_cbKeyFile.Checked && (!strKeyFile.Equals(KPRes.NoKeyFileSpecifiedMeta)) &&
                (bIsKeyProv == false))
            {
                try { m_pKey.AddUserKey(new KcpKeyFile(strKeyFile)); }
                catch(Exception exKF)
                {
                    MessageService.ShowWarning(strKeyFile, KPRes.KeyFileError, exKF);
                    return false;
                }
            }
            else if(m_cbKeyFile.Checked && (!strKeyFile.Equals(KPRes.NoKeyFileSpecifiedMeta)) &&
                (bIsKeyProv == true))
            {
                byte[] pbCustomKey = Program.KeyProviderPool.GetKey(strKeyFile);

                try { m_pKey.AddUserKey(new KcpCustomKey(pbCustomKey)); }
                catch(Exception exCKP)
                {
                    MessageService.ShowWarning(strKeyFile, KPRes.KeyFileError, exCKP);
                    return false;
                }

                if((pbCustomKey != null) && (pbCustomKey.Length > 0))
                    Array.Clear(pbCustomKey, 0, pbCustomKey.Length);
            }

            if(m_cbUserAccount.Checked)
            {
                try { m_pKey.AddUserKey(new KcpUserAccount()); }
                catch(Exception exUA)
                {
                    MessageService.ShowWarning(exUA);
                    return false;
                }
            }

            return true;
        }
开发者ID:jonbws,项目名称:strengthreport,代码行数:81,代码来源:KeyCreationForm.cs

示例11: SetupAppWithDatabase

        protected TestKp2aApp SetupAppWithDatabase(string filename)
        {
            TestKp2aApp app = CreateTestKp2aApp();

            IOConnectionInfo ioc = new IOConnectionInfo {Path = filename};
            Database db = app.CreateNewDatabase();
            if (filename.EndsWith(".kdb"))
            {
                db.DatabaseFormat = new KdbDatabaseFormat(app);
            }

            db.KpDatabase = new PwDatabase();

            CompositeKey compositeKey = new CompositeKey();
            compositeKey.AddUserKey(new KcpPassword(DefaultPassword));
            if (!String.IsNullOrEmpty(DefaultKeyfile))
                compositeKey.AddUserKey(new KcpKeyFile(DefaultKeyfile));
            db.KpDatabase.New(ioc, compositeKey);

            db.KpDatabase.KeyEncryptionRounds = 3;
            db.KpDatabase.Name = "Keepass2Android Testing Password Database";

            // Set Database state
            db.Root = db.KpDatabase.RootGroup;
            db.Loaded = true;
            db.SearchHelper = new SearchDbHelper(app);

            // Add a couple default groups
            db.KpDatabase.RootGroup.AddGroup(new PwGroup(true, true, "Internet", PwIcon.Key), true);

            mailGroup = new PwGroup(true, true, "eMail", PwIcon.UserCommunication);
            db.KpDatabase.RootGroup.AddGroup(mailGroup, true);

            mailGroup.AddGroup(new PwGroup(true, true, "business", PwIcon.BlackBerry), true);

            mailEntry = new PwEntry(true, true);
            mailEntry.Strings.Set(PwDefs.UserNameField, new ProtectedString(
                                                            true, "[email protected]"));
            mailEntry.Strings.Set(PwDefs.TitleField, new ProtectedString(
                                                         true, "[email protected] Entry"));
            mailGroup.AddEntry(mailEntry, true);

            db.KpDatabase.RootGroup.AddGroup(new PwGroup(true, true, "eMail2", PwIcon.UserCommunication), true);

            return app;
        }
开发者ID:pythe,项目名称:wristpass,代码行数:46,代码来源:TestBase.cs

示例12: CreateCompositeKey

        private bool CreateCompositeKey(out CompositeKey compositeKey, out string errorMessage)
        {
            errorMessage = null;
            //no need to check for validity of password because if this method is called, the Ok button was enabled (i.e. there was a valid password)
            compositeKey = new CompositeKey();
            compositeKey.AddUserKey(new KcpPassword(_password));
            if (KeyProviderType == KeyProviders.KeyFile)
            {
                try
                {
                    if (_keyFileOrProvider == "")
                        throw new System.IO.FileNotFoundException();
                    var ioc = IOConnectionInfo.UnserializeFromString(_keyFileOrProvider);
                    using (var stream = App.Kp2a.GetFileStorage(ioc).OpenFileForRead(ioc))
                    {
                        byte[] keyfileData = StreamToMemoryStream(stream).ToArray();
                        compositeKey.AddUserKey(new KcpKeyFile(keyfileData, ioc, true));
                    }
                }
                catch (System.IO.FileNotFoundException e)
                {
                    Kp2aLog.Log(e.ToString());
                    errorMessage = App.Kp2a.GetResourceString(UiStringKey.keyfile_does_not_exist);
                    return false;
                }
                catch (Exception e)
                {
                    Kp2aLog.Log(e.ToString());
                    errorMessage = e.Message;
                    return false;
                }
            }
            else if (KeyProviderType == KeyProviders.Otp)
            {
                try
                {
                    var lOtps = GetOtpsFromUi();
                    Kp2aLog.Log("received " + lOtps.Count + " otps.");
                    OathHotpKeyProv.CreateOtpSecret(lOtps, _otpInfo);
                }
                catch (Exception e)
                {
                    Kp2aLog.Log(e.ToString());
                    errorMessage = GetString(Resource.String.OtpKeyError);

                    return false;
                }
                compositeKey.AddUserKey(new KcpCustomKey(OathHotpKeyProv.Name, _otpInfo.Secret, true));
            }
            else if ((KeyProviderType == KeyProviders.OtpRecovery) || (KeyProviderType == KeyProviders.ChalRecovery))
            {
                Spinner stpDataFmtSpinner = FindViewById<Spinner>(Resource.Id.otpsecret_format_spinner);
                EditText secretEdit = FindViewById<EditText>(Resource.Id.pass_otpsecret);

                byte[] pbSecret = EncodingUtil.ParseKey(secretEdit.Text, (OtpDataFmt) stpDataFmtSpinner.SelectedItemPosition);
                if (pbSecret != null)
                {
                    compositeKey.AddUserKey(new KcpCustomKey(OathHotpKeyProv.Name, pbSecret, true));
                }
                else
                {
                    errorMessage = GetString(Resource.String.CouldntParseOtpSecret);
                    return false;
                }
            }
            else if (KeyProviderType == KeyProviders.Challenge)
            {
                compositeKey.AddUserKey(new KcpCustomKey(KeeChallengeProv.Name, _challengeSecret, true));
            }
            return true;
        }
开发者ID:pythe,项目名称:wristpass,代码行数:71,代码来源:PasswordActivity.cs

示例13: CreateCompositeKey

        private bool CreateCompositeKey()
        {
            m_pKey = new CompositeKey();

            if(m_secPassword.ContentsEqualTo(m_secRepeat) == false)
            {
                MessageService.ShowWarning(KPRes.PasswordRepeatFailed);
                return false;
            }

            if(m_secPassword.TextLength == 0)
            {
                if(!MessageService.AskYesNo(KPRes.EmptyMasterPw +
                    MessageService.NewParagraph + KPRes.EmptyMasterPwHint +
                    MessageService.NewParagraph + KPRes.EmptyMasterPwQuestion,
                    null, false))
                {
                    return false;
                }
            }

            uint uMinLen = Program.Config.Security.MasterPassword.MinimumLength;
            if(m_secPassword.TextLength < uMinLen)
            {
                string strML = KPRes.MasterPasswordMinLengthFailed;
                strML = strML.Replace(@"{PARAM}", uMinLen.ToString());
                MessageService.ShowWarning(strML);
                return false;
            }

            byte[] pb = m_secPassword.ToUtf8();

            uint uMinQual = Program.Config.Security.MasterPassword.MinimumQuality;
            if(QualityEstimation.EstimatePasswordBits(pb) < uMinQual)
            {
                string strMQ = KPRes.MasterPasswordMinQualityFailed;
                strMQ = strMQ.Replace(@"{PARAM}", uMinQual.ToString());
                MessageService.ShowWarning(strMQ);
                Array.Clear(pb, 0, pb.Length);
                return false;
            }

            string strValRes = Program.KeyValidatorPool.Validate(pb,
                KeyValidationType.MasterPassword);
            if(strValRes != null)
            {
                MessageService.ShowWarning(strValRes);
                Array.Clear(pb, 0, pb.Length);
                return false;
            }

            m_pKey.AddUserKey(new KcpPassword(pb));
            Array.Clear(pb, 0, pb.Length);

            return true;
        }
开发者ID:db48x,项目名称:KeeFox,代码行数:56,代码来源:KeyCreationSimpleForm.cs

示例14: CreateCompositeKey

		private bool CreateCompositeKey()
		{
			m_pKey = new CompositeKey();

			if(m_cbPassword.Checked) // Use a password
			{
				byte[] pb = m_secPassword.ToUtf8();
				m_pKey.AddUserKey(new KcpPassword(pb));
				MemUtil.ZeroByteArray(pb);
			}

			string strKeyFile = m_cmbKeyFile.Text;
			Debug.Assert(strKeyFile != null); if(strKeyFile == null) strKeyFile = string.Empty;
			bool bIsProvKey = Program.KeyProviderPool.IsKeyProvider(strKeyFile);

			if(m_cbKeyFile.Checked && !strKeyFile.Equals(KPRes.NoKeyFileSpecifiedMeta) &&
				!bIsProvKey)
			{
				if(!ValidateKeyFile()) return false;

				try { m_pKey.AddUserKey(new KcpKeyFile(strKeyFile)); }
				catch(Exception)
				{
					MessageService.ShowWarning(strKeyFile, KPRes.KeyFileError);
					return false;
				}
			}
			else if(m_cbKeyFile.Checked && !strKeyFile.Equals(KPRes.NoKeyFileSpecifiedMeta) &&
				bIsProvKey)
			{
				KeyProvider kp = Program.KeyProviderPool.Get(strKeyFile);
				if((kp != null) && m_bSecureDesktop)
				{
					if(!kp.SecureDesktopCompatible)
					{
						MessageService.ShowWarning(KPRes.KeyProvIncmpWithSD,
							KPRes.KeyProvIncmpWithSDHint);
						return false;
					}
				}

				KeyProviderQueryContext ctxKP = new KeyProviderQueryContext(
					m_ioInfo, false, m_bSecureDesktop);

				bool bPerformHash;
				byte[] pbProvKey = Program.KeyProviderPool.GetKey(strKeyFile, ctxKP,
					out bPerformHash);
				if((pbProvKey != null) && (pbProvKey.Length > 0))
				{
					try { m_pKey.AddUserKey(new KcpCustomKey(strKeyFile, pbProvKey, bPerformHash)); }
					catch(Exception exCKP)
					{
						MessageService.ShowWarning(exCKP);
						return false;
					}

					MemUtil.ZeroByteArray(pbProvKey);
				}
				else return false; // Provider has shown error message
			}

			if(m_cbUserAccount.Checked)
			{
				try { m_pKey.AddUserKey(new KcpUserAccount()); }
				catch(Exception exUA)
				{
					MessageService.ShowWarning(exUA);
					return false;
				}
			}

			return true;
		}
开发者ID:joshuadugie,项目名称:KeePass-2.x,代码行数:73,代码来源:KeyPromptForm.cs

示例15: CreateCompositeKey

        private bool CreateCompositeKey()
        {
            m_pKey = new CompositeKey();

            if(m_cbPassword.Checked) // Use a password
            {
                if(!m_icgPassword.ValidateData(true)) return false;

                uint uPwLen = m_icgPassword.PasswordLength;
                if(uPwLen == 0)
                {
                    if(!MessageService.AskYesNo(KPRes.EmptyMasterPw +
                        MessageService.NewParagraph + KPRes.EmptyMasterPwHint +
                        MessageService.NewParagraph + KPRes.EmptyMasterPwQuestion,
                        null, false))
                    {
                        return false;
                    }
                }

                uint uMinLen = Program.Config.Security.MasterPassword.MinimumLength;
                if(uPwLen < uMinLen)
                {
                    string strML = KPRes.MasterPasswordMinLengthFailed;
                    strML = strML.Replace(@"{PARAM}", uMinLen.ToString());
                    MessageService.ShowWarning(strML);
                    return false;
                }

                byte[] pb = m_icgPassword.GetPasswordUtf8();

                uint uMinQual = Program.Config.Security.MasterPassword.MinimumQuality;
                if(QualityEstimation.EstimatePasswordBits(pb) < uMinQual)
                {
                    string strMQ = KPRes.MasterPasswordMinQualityFailed;
                    strMQ = strMQ.Replace(@"{PARAM}", uMinQual.ToString());
                    MessageService.ShowWarning(strMQ);
                    Array.Clear(pb, 0, pb.Length);
                    return false;
                }

                string strValRes = Program.KeyValidatorPool.Validate(pb,
                    KeyValidationType.MasterPassword);
                if(strValRes != null)
                {
                    MessageService.ShowWarning(strValRes);
                    Array.Clear(pb, 0, pb.Length);
                    return false;
                }

                m_pKey.AddUserKey(new KcpPassword(pb));
                Array.Clear(pb, 0, pb.Length);
            }

            string strKeyFile = m_cmbKeyFile.Text;
            bool bIsKeyProv = Program.KeyProviderPool.IsKeyProvider(strKeyFile);

            if(m_cbKeyFile.Checked && (!strKeyFile.Equals(KPRes.NoKeyFileSpecifiedMeta)) &&
                !bIsKeyProv)
            {
                try { m_pKey.AddUserKey(new KcpKeyFile(strKeyFile, true)); }
                catch(InvalidDataException exID) // Selected database file
                {
                    MessageService.ShowWarning(strKeyFile, exID);
                    return false;
                }
                catch(Exception exKF)
                {
                    MessageService.ShowWarning(strKeyFile, KPRes.KeyFileError, exKF);
                    return false;
                }
            }
            else if(m_cbKeyFile.Checked && (!strKeyFile.Equals(KPRes.NoKeyFileSpecifiedMeta)) &&
                bIsKeyProv)
            {
                KeyProviderQueryContext ctxKP = new KeyProviderQueryContext(
                    m_ioInfo, true, false);

                bool bPerformHash;
                byte[] pbCustomKey = Program.KeyProviderPool.GetKey(strKeyFile, ctxKP,
                    out bPerformHash);
                if((pbCustomKey != null) && (pbCustomKey.Length > 0))
                {
                    try { m_pKey.AddUserKey(new KcpCustomKey(strKeyFile, pbCustomKey, bPerformHash)); }
                    catch(Exception exCKP)
                    {
                        MessageService.ShowWarning(exCKP);
                        return false;
                    }

                    Array.Clear(pbCustomKey, 0, pbCustomKey.Length);
                }
                else return false; // Provider has shown error message
            }

            if(m_cbUserAccount.Checked)
            {
                try { m_pKey.AddUserKey(new KcpUserAccount()); }
                catch(Exception exUA)
                {
//.........这里部分代码省略.........
开发者ID:ashwingj,项目名称:keepass2,代码行数:101,代码来源:KeyCreationForm.cs


注:本文中的KeePassLib.Keys.CompositeKey.AddUserKey方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。