GetUserKey() public method

Get the first user key of a specified type.
public GetUserKey ( Type tUserKeyType ) : IUserKey
tUserKeyType System.Type Type of the user key to get.
return IUserKey
コード例 #1
0
ファイル: AceDefaults.cs プロジェクト: saadware/kpn
        public void SetKeySources(IOConnectionInfo iocDb, CompositeKey cmpKey)
        {
            string strID = GetKeyAssocID(iocDb);
            int idx = GetKeyAssocIndex(strID);

            if((cmpKey == null) || !m_bRememberKeySources)
            {
                if(idx >= 0) m_vKeySources.RemoveAt(idx);
                return;
            }

            AceKeyAssoc a = new AceKeyAssoc();
            a.DatabasePath = strID;

            IUserKey kcpFile = cmpKey.GetUserKey(typeof(KcpKeyFile));
            if(kcpFile != null)
            {
                string strKeyFile = ((KcpKeyFile)kcpFile).Path;
                if(!string.IsNullOrEmpty(strKeyFile) && !StrUtil.IsDataUri(strKeyFile))
                {
                    if(!UrlUtil.IsAbsolutePath(strKeyFile))
                        strKeyFile = UrlUtil.MakeAbsolutePath(WinUtil.GetExecutable(),
                            strKeyFile);

                    a.KeyFilePath = strKeyFile;
                }
            }

            IUserKey kcpCustom = cmpKey.GetUserKey(typeof(KcpCustomKey));
            if(kcpCustom != null)
                a.KeyProvider = ((KcpCustomKey)kcpCustom).Name;

            IUserKey kcpUser = cmpKey.GetUserKey(typeof(KcpUserAccount));
            a.UserAccount = (kcpUser != null);

            bool bAtLeastOne = ((a.KeyFilePath.Length > 0) ||
                (a.KeyProvider.Length > 0) || a.UserAccount);
            if(bAtLeastOne)
            {
                if(idx >= 0) m_vKeySources[idx] = a;
                else m_vKeySources.Add(a);
            }
            else if(idx >= 0) m_vKeySources.RemoveAt(idx);
        }
コード例 #2
0
ファイル: KdbFile.cs プロジェクト: kusuriya/PasswordKeeper
		private static KdbErrorCode SetDatabaseKey(KdbManager mgr, CompositeKey pwKey)
		{
			KdbErrorCode e;

			bool bPassword = pwKey.ContainsType(typeof(KcpPassword));
			bool bKeyFile = pwKey.ContainsType(typeof(KcpKeyFile));

			string strPassword = (bPassword ? (pwKey.GetUserKey(
				typeof(KcpPassword)) as KcpPassword).Password.ReadString() : string.Empty);
			string strKeyFile = (bKeyFile ? (pwKey.GetUserKey(
				typeof(KcpKeyFile)) as KcpKeyFile).Path : string.Empty);

			if(bPassword && bKeyFile)
				e = mgr.SetMasterKey(strKeyFile, true, strPassword, IntPtr.Zero, false);
			else if(bPassword && !bKeyFile)
				e = mgr.SetMasterKey(strPassword, false, null, IntPtr.Zero, false);
			else if(!bPassword && bKeyFile)
				e = mgr.SetMasterKey(strKeyFile, true, null, IntPtr.Zero, false);
			else if(pwKey.ContainsType(typeof(KcpUserAccount)))
				throw new Exception(KPRes.KdbWUA);
			else throw new Exception(KLRes.InvalidCompositeKey);

			return e;
		}