Example #1
0
        public void TestDecrytor()
        {
            var keyValue = RC2Crypto.CreateKey();

            String encryptorStr = RC2Crypto.Encryptor(input, keyValue.Key, keyValue.Value);
            String decryptorStr = RC2Crypto.Decryptor(encryptorStr, keyValue.Key, keyValue.Value);

            Assert.IsNotNull(encryptorStr);
            Assert.IsTrue(encryptorStr.Length > 0);
            Console.WriteLine("密文:{0}", encryptorStr);
            Assert.IsNotNull(decryptorStr);
            Assert.IsTrue(decryptorStr.Length > 0);
            Console.WriteLine("明文:{0}", decryptorStr);
            Assert.IsTrue(decryptorStr.Equals(input));
        }
Example #2
0
        private void btn_Decrypt_Click(object sender, EventArgs e)
        {
            String key  = textBox_Key.Text.Trim(),
                   iv   = textBox_IV.Text.Trim(),
                   body = textBox_Body.Text.Trim();

            if (String.IsNullOrEmpty(key))
            {
                MessageBox.Show("秘钥不能为空!", "温馨提示");
                return;
            }

            if (String.IsNullOrEmpty(iv) && isIvEncrypt())
            {
                MessageBox.Show("偏移量不能为空!", "温馨提示");
                return;
            }


            if (String.IsNullOrEmpty(body))
            {
                MessageBox.Show("待处理文本不能为空!", "温馨提示");
                return;
            }

            try
            {
                if (isIvEncrypt())
                {
                    textBox_Result.Text = RC2Crypto.Decryptor(body, key, iv);
                }
                else
                {
                    textBox_Result.Text = RC2Crypto.Decryptor(body, key);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("解密失败:" + ex.Message, "错误");
            }
        }
Example #3
0
        public void TestDecrytorNoIv()
        {
            String key = RC2Crypto.CreateKeyNoIv();

            Assert.IsNotNull(key);
            Assert.IsTrue(key.Length > 0);
            Console.WriteLine("Key:{0}", key);

            String encryptorStr = RC2Crypto.Encryptor(input, key);

            Assert.IsNotNull(encryptorStr);
            Assert.IsTrue(encryptorStr.Length > 0);
            Console.WriteLine("密文:{0}", encryptorStr);

            String decryptorStr = RC2Crypto.Decryptor(encryptorStr, key);

            Assert.IsNotNull(decryptorStr);
            Assert.IsTrue(decryptorStr.Length > 0);
            Console.WriteLine("正文:{0}", decryptorStr);
            Assert.IsTrue(decryptorStr.Equals(input));
        }