コード例 #1
0
        internal KeyListViewItem(string txt, GnuKey key) : base(txt)
        {
            Key = key;

            SubItems.Add(new ListViewItem.ListViewSubItem(this, key.Expiry));
            SubItems.Add(new ListViewItem.ListViewSubItem(this, key.KeyId));
        }
コード例 #2
0
		private static void AddGnuKeyIfUsable(string key, List<GnuKey> keys)
		{
			var match = Regex.Match(key, @"<(.*)>");
			if (!match.Success)
				return;

			var k = new GnuKey
			{
				Key = match.Groups[1].Value,
				KeyDisplay = key
			};

			keys.Add(k);
		}
コード例 #3
0
ファイル: Recipient.cs プロジェクト: ktw/OutlookPrivacyPlugin
        private void OldPassphrase_Load(object sender, EventArgs e)
        {
            IList <GnuKey> keys = Globals.OutlookPrivacyPlugin.GetKeysForEncryption();

            KeyBox.DataSource    = keys;
            KeyBox.DisplayMember = "KeyDisplay";
            KeyBox.ValueMember   = "Key";

            if (KeyBox.Items.Count <= 0)
            {
                // No keys available, no use in showing this dialog at all
                Hide();
                return;
            }

            int boxHeight = (keys.Count > 10) ? KeyBox.ItemHeight * 10 : KeyBox.ItemHeight * keys.Count;

            KeyBox.Height = boxHeight + 5;
            Height        = boxHeight + 90;

            // Enlarge dialog to fit the longest key
            using (Graphics g = CreateGraphics())
            {
                int maxSize = Width;
                foreach (GnuKey key in keys)
                {
                    int textWidth = (int)g.MeasureString(key.KeyDisplay, KeyBox.Font).Width + 50;
                    if (textWidth > maxSize)
                    {
                        maxSize = textWidth;
                    }
                }
                Width = maxSize;
                CenterToScreen();
            }

            for (int i = 0; i < KeyBox.Items.Count; i++)
            {
                GnuKey recipient = (GnuKey)KeyBox.Items[i];
#if DISABLED
                KeyBox.SetItemChecked(i, _defaultKeys.Contains(recipient.Key));
#else
                // Update to support CN from X.400 mail address format.
                // Enable item if the associated key starts with one of the available _defaultKeys (hence a prefix match).
                KeyBox.SetItemChecked(i,
                                      null != _defaultKeys.Find(delegate(string gnuKey) { return(recipient.Key.StartsWith(gnuKey)); }));
#endif
            }
        }
コード例 #4
0
        public IList<GnuKey> GetKeysForEncryption()
        {
            var crypto = new PgpCrypto(new CryptoContext());
            List<GnuKey> keys = new List<GnuKey>();

            foreach (string key in crypto.GetPublicKeyUserIdsForEncryption())
            {
                var match = Regex.Match(key, @"<(.*)>");
                if (!match.Success)
                    continue;

                GnuKey k = new GnuKey();
                k.Key = match.Groups[1].Value;
                k.KeyDisplay = key;

                keys.Add(k);
            }

            return keys;
        }
コード例 #5
0
		internal KeyListViewItem(string txt, GnuKey key): base(txt)
		{
			Key = key;

			SubItems.Add(new ListViewItem.ListViewSubItem(this, key.Expiry));
			SubItems.Add(new ListViewItem.ListViewSubItem(this, key.KeyId));
		}
コード例 #6
0
		public IList<GnuKey> GetKeysForEncryption()
		{
			var crypto = new PgpCrypto(new CryptoContext());
			var keys = new List<GnuKey>();

			foreach (PgpPublicKey key in crypto.GetPublicKeyUserIdsForEncryption())
			{
				foreach (string user in key.GetUserIds())
				{
					var match = Regex.Match(user, @"<(.*)>");
					if (!match.Success)
						continue;

					var k = new GnuKey();
					k.Key = match.Groups[1].Value;
					k.KeyDisplay = user;

					var fingerprint = key.GetFingerprint();
					k.KeyId =
						fingerprint[fingerprint.Length - 4].ToString("X2") +
						fingerprint[fingerprint.Length - 3].ToString("X2") +
						fingerprint[fingerprint.Length - 2].ToString("X2") +
						fingerprint[fingerprint.Length - 1].ToString("X2");

					if (key.GetValidSeconds() != 0)
						k.Expiry = key.CreationTime.AddSeconds(key.GetValidSeconds()).ToShortDateString();

					keys.Add(k);
				}
			}

			return keys;
		}