示例#1
0
 public void RemoveEntry(KeyEntry entry)
 {
     if (_privateKeys.Contains(entry))
     {
         _privateKeys.Remove(entry);
         Save();
         RaisePrivateKeyUpdatedEvent();
         return;
     }
     if (_publicKeys.Contains(entry))
     {
         _publicKeys.Remove(entry);
         Save();
         RaisePublicKeyUpdatedEvent();
         return;
     }
 }
示例#2
0
        private void btnEncryptText_Click(object sender, EventArgs e)
        {
            if (txtEncryptPlain.Text.Length == 0)
            {
                return;
            }
            try {
                KeyEntry publicKeyEntry = cbPublicKeys2.SelectedItem as KeyEntry;
                if (publicKeyEntry == null)
                {
                    throw new Exception("暗号化に利用する公開鍵を選択してください");
                }
                ECDomainNames      domain;
                byte[]             publicKey   = ParsePublicKey(publicKeyEntry.Key, out domain);
                string             encryptType = null;
                SymmetricAlgorithm algo        = null;
                switch (cbEncryptCrypto.SelectedIndex)
                {
                case 0:
                    encryptType = "ecies+xor";
                    algo        = null;
                    break;

                case 1:
                case 2:
                    encryptType    = "ecies+camellia";
                    algo           = new CamelliaManaged();
                    algo.BlockSize = 128;
                    if (cbEncryptCrypto.SelectedIndex == 1)
                    {
                        encryptType += "128";
                        algo.KeySize = 128;
                    }
                    else
                    {
                        encryptType += "256";
                        algo.KeySize = 256;
                    }
                    break;

                case 3:
                case 4:
                    encryptType    = "ecies+rijndael";
                    algo           = new openCrypto.RijndaelManaged();
                    algo.BlockSize = 128;
                    if (cbEncryptCrypto.SelectedIndex == 3)
                    {
                        encryptType += "128";
                        algo.KeySize = 128;
                    }
                    else
                    {
                        encryptType += "256";
                        algo.KeySize = 256;
                    }
                    break;

                default:
                    throw new CryptographicException("Unknown");
                }
                if (algo != null)
                {
                    algo.Mode    = CipherMode.CBC;
                    algo.Padding = PaddingMode.PKCS7;
                }
                ECIES ecies = new ECIES(domain, algo);
                ecies.Parameters.PublicKey = publicKey;
                string encrypted = Convert.ToBase64String(ecies.Encrypt(Encoding.UTF8.GetBytes(txtEncryptPlain.Text)));
                txtEncryptCipher.Text = encryptType + "=" + encrypted;
            } catch (Exception ex) {
                MessageBox.Show(ex.Message);
            }
        }