コード例 #1
0
        public CompositeKey GetCompositeKey(KeyCipher keyCipher)
        {
            var password     = keyCipher.UnProtect(_protectedPassword);
            var compositeKey = new CompositeKey();

            foreach (var data in _keys)
            {
                IUserKey key     = null;
                byte[]   rawData = null;
                if (data.KcpType != KcpType.kcpUserAccount)
                {
                    rawData = keyCipher.Decrypt(data.EncryptedData, password);
                }

                try
                {
                    switch (data.KcpType)
                    {
                    case KcpType.kcpCustomKey:
                        key = new KcpCustomKey(data.CustomName, rawData, false);
                        break;

                    case KcpType.kcpPassword:
                        key = new KcpPassword(rawData);
                        break;

                    case KcpType.kcpKeyFile:
                        key = new KcpKeyFile(Encoding.UTF8.GetString(rawData));
                        break;

                    case KcpType.kcpUserAccount:
                        key = new KcpUserAccount();
                        break;
                    }
                }
                finally
                {
                    if (rawData != null)
                    {
                        MemUtil.ZeroByteArray(rawData);
                    }
                }

                Debug.Assert(key != null);
                compositeKey.AddUserKey(key);
            }

            return(compositeKey);
        }
コード例 #2
0
        public ProtectedKey(CompositeKey compositeKey, KeyCipher keyCipher)
        {
            var password = keyCipher.GeneratePassword();

            _protectedPassword = keyCipher.Protect(password);
            _keys = new List <KcpData>();

            foreach (var key in compositeKey.UserKeys)
            {
                KcpData data;

                var p  = key as KcpPassword;
                var kf = key as KcpKeyFile;
                var ck = key as KcpCustomKey;

                if (p != null)
                {
                    if (p.Password != null)
                    {
                        data = new KcpData(KcpType.kcpPassword, keyCipher.Encrypt(p.Password, password));
                    }
                    else
                    {
                        data = new KcpData(KcpType.kcpCustomKey, keyCipher.Encrypt(p.KeyData, password), p.ToString());
                    }
                }
                else if (kf != null)
                {
                    data = new KcpData(KcpType.kcpKeyFile, keyCipher.Encrypt(new ProtectedString(false, kf.Path), password));
                }
                else if (key is KcpUserAccount)
                {
                    data = new KcpData(KcpType.kcpUserAccount);
                }
                else
                {
                    Debug.Assert(ck != null, "Unknown key type");
                    var name = ck != null ? ck.Name : key.ToString();
                    data = new KcpData(KcpType.kcpCustomKey, keyCipher.Encrypt(key.KeyData, password), name);
                }

                _keys.Add(data);
            }
        }
コード例 #3
0
 public KeyManager(IntPtr windowHandle)
 {
     _keyStorage = new KeyStorage();
     _keyCipher  = new KeyCipher(Settings.ConfirmationMessage, windowHandle);
 }
コード例 #4
0
 public KeyManager(IntPtr windowHandle)
 {
     _keePassMainWindowHandle = windowHandle;
     _keyCipher  = new KeyCipher(windowHandle);
     _keyStorage = KeyStorageFactory.Create(_keyCipher.AuthProvider);
 }
コード例 #5
0
 public static ProtectedKey Create(CompositeKey compositeKey, KeyCipher keyCipher)
 {
     return(new ProtectedKey(compositeKey, keyCipher));
 }