コード例 #1
0
        public static bool Update(KeyStoreDB keyStoreDb, long keyId, string trust)
        {
            if (keyStoreDb == null)
            {
                throw new ArgumentNullException("keyStoreDb");
            }
            if (keyId == 0)
            {
                throw new ArgumentOutOfRangeException("keyId");
            }
            if (string.IsNullOrEmpty(trust))
            {
                throw new ArgumentNullException("trust");
            }


            KeyStores updRow = keyStoreDb.KeyStores.Find(keyId);

            switch (updRow.KeyType)
            {
            case "Public":
                if (pubKeyLevels.Contains(trust.ToLower()))
                {
                    updRow.OwnerTrust = trust;
                }
                else
                {
                    updRow.OwnerTrust = string.Empty;
                }
                break;

            case "Secret":
                if (secKeyLevel.Equals(trust.ToLower()))
                {
                    updRow.OwnerTrust = trust;
                }
                else
                {
                    updRow.OwnerTrust = trust;
                }
                break;

            default:
                break;
            }
            keyStoreDb.SaveChanges();

            return(true);
        }
コード例 #2
0
        private bool RemovePublicKeyForSecretKey(long keyId, KeyStoreDB keyStoreDB)
        {
            KeyStores pubKeyDelete = keyStoreDB.KeyStores.Find(keyId);

            if (pubKeyDelete != null)
            {
                KeyUsers pubUserDelete = keyStoreDB.KeyUsers.Find(keyId);
                if (pubUserDelete != null)
                {
                    keyStoreDB.KeyUsers.Remove(pubUserDelete);
                }
                keyStoreDB.KeyStores.Remove(pubKeyDelete);
                keyStoreDB.SaveChanges();
            }
            return(true);
        }
コード例 #3
0
        public void UpdateDbSecretKey(PgpSecretKey key, string keyExportName)
        {
            Stream outFile  = File.Create(keyExportName);
            Stream outArmor = new ArmoredOutputStream(outFile);
            string secKey   = string.Empty;

            key.Encode(outArmor);
            outArmor.Close();
            using (StreamReader rdr = new StreamReader(outFile)) {
                rdr.BaseStream.Position = 0;
                secKey = rdr.ReadToEnd();
            }
            KeyStores updKey = m_keyStoreDb.KeyStores.Find(key.KeyId);

            updKey.ArmouredKeyFile = secKey;
            m_keyStoreDb.SaveChanges();
        }
コード例 #4
0
        public KeyView(KeyStores keyData, long userId)
        {
            this.KeyType    = keyData.KeyType;
            this.OwnerTrust = keyData.OwnerTrust;
            StringBuilder buildFingerprint = new StringBuilder();

            for (int x = 0; x < keyData.Fingerprint.Length; x++)
            {
                buildFingerprint.Append(string.Format("{0} ", keyData.Fingerprint[x].ToString("X2")));
            }
            this.Fingerprint     = buildFingerprint.ToString().TrimEnd();;
            this.IsEncryptionKey = keyData.IsEncryptionKey;
            this.IsSigningKey    = keyData.IsSigningKey;
            this.IsMasterKey     = keyData.IsMasterKey;
            this.ValidDays       = keyData.ValidDays;
            this.CreationTime    = keyData.CreationTime;
            this.KeyStoreId      = keyData.KeyStoreID;
            KeyUsers userData = keyData.KeyUsers.Where(u => u.KeyUserID == userId).FirstOrDefault();

            if (userData != null)
            {
                this.KeyUserId = userData.KeyUserID;
                if (userData.UserName != null)
                {
                    this.UserName = userData.UserName;
                }
                if (userData.Email != null)
                {
                    this.Email = userData.Email;
                }
                if (userData.EncryptionType != null)
                {
                    this.EncryptionType = userData.EncryptionType;
                }
                this.KeySize = userData.KeySize;
            }
        }