Пример #1
0
 private bool Decrypt()
 {
     _items = null; // will cause it to reinitiailize above
     if (Key != null)
     {
         string password = Key.PrivateKeyDecrypt(Key.Password);
         VaultItemsByVaultId.Each(item =>
         {
             string key = item.Key.AesPasswordDecrypt(password);
             DecryptedVaultItem value = new DecryptedVaultItem(item, Key);
             Items.Add(key, value);
         });
         return(true);
     }
     return(false);
 }
Пример #2
0
        public string this[string key]
        {
            get
            {
                if (Items.ContainsKey(key))
                {
                    return(Items[key].Value);
                }
                else
                {
                    Decrypt();
                    if (Items.ContainsKey(key))
                    {
                        return(Items[key].Value);
                    }
                }

                return(null);
            }
            set
            {
                lock (writeLock)
                {
                    if (Decrypt())
                    {
                        if (Items.ContainsKey(key))
                        {
                            Items[key].Value = value;
                        }
                        else
                        {
                            VaultItem item     = VaultItemsByVaultId.AddNew();
                            string    password = Key.PrivateKeyDecrypt(Key.Password);
                            item.Key   = key.AesPasswordEncrypt(password);
                            item.Value = value.AesPasswordEncrypt(password);
                            item.Save();
                            Items[key] = new DecryptedVaultItem(item, Key);
                        }
                    }
                }
            }
        }