Beispiel #1
0
        public void ImportKey(VaultKeyInfo keyInfo, Database db = null)
        {
            VaultKey key = VaultKeysByVaultId.AddNew();

            key.RsaKey   = keyInfo.RsaKey;
            key.Password = keyInfo.Password;
            key.Save(db);
            _items = null;
            ChildCollections.Clear();
        }
Beispiel #2
0
        private static VaultKey CreateFromFilter(IQueryFilter filter, Database database = null)
        {
            Database db  = database ?? Db.For <VaultKey>();
            var      dao = new VaultKey();

            filter.Parameters.Each(p =>
            {
                dao.Property(p.ColumnName, p.Value);
            });
            dao.Save(db);
            return(dao);
        }
Beispiel #3
0
        public VaultKeyInfo ExportKey(Database db = null)
        {
            db = db ?? Database;
            VaultKey key = VaultKeysByVaultId.FirstOrDefault();

            _items = null;
            VaultKeysByVaultId.Delete(db);
            ChildCollections.Clear();
            VaultKeyInfo result = key.CopyAs <VaultKeyInfo>();

            return(result);
        }
Beispiel #4
0
 public ActionResult Update(Bam.Net.Encryption.VaultKey dao)
 {
     try
     {
         dao.Save();
         return(Json(new { Success = true, Message = "", Dao = dao.ToJsonSafe() }));
     }
     catch (Exception ex)
     {
         return(GetErrorResult(ex));
     }
 }
Beispiel #5
0
        /// <summary>
        /// Create a Vault in the specified database by the specified
        /// name using the specified password to create it if it
        /// doesn't exist
        /// </summary>
        /// <param name="database"></param>
        /// <param name="name"></param>
        /// <param name="password"></param>
        /// <param name="rsaKeyLength"></param>
        /// <returns></returns>
        public static Vault Create(Database database, string name, string password, RsaKeyLength rsaKeyLength = RsaKeyLength._1024)
        {
            Vault result = Vault.OneWhere(c => c.Name == name, database);

            if (result == null)
            {
                result      = new Vault();
                result.Name = name;
                result.Save(database);
                VaultKey key = result.VaultKeysByVaultId.JustOne(database, false);
                AsymmetricCipherKeyPair keys = RsaKeyGen.GenerateKeyPair(rsaKeyLength);
                key.RsaKey   = keys.ToPem();
                key.Password = password.EncryptWithPublicKey(keys);
                key.Save(database);
            }

            return(result);
        }
Beispiel #6
0
 public ActionResult Delete(long id)
 {
     try
     {
         string msg = "";
         Bam.Net.Encryption.VaultKey dao = Bam.Net.Encryption.VaultKey.OneWhere(c => c.KeyColumn == id);
         if (dao != null)
         {
             dao.Delete();
         }
         else
         {
             msg = string.Format("The specified id ({0}) was not found in the table (VaultKey)", id);
         }
         return(Json(new { Success = true, Message = msg, Dao = "" }));
     }
     catch (Exception ex)
     {
         return(GetErrorResult(ex));
     }
 }
Beispiel #7
0
 public ActionResult Create(Bam.Net.Encryption.VaultKey dao)
 {
     return(Update(dao));
 }
Beispiel #8
0
 public DecryptedVaultItem(VaultItem item, VaultKey key)
 {
     this.Item     = item;
     this.VaultKey = key;
 }