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)) { MessageBox.Show("偏移量不能为空!", "温馨提示"); return; } if (String.IsNullOrEmpty(body)) { MessageBox.Show("待处理文本不能为空!", "温馨提示"); return; } try { textBox_Result.Text = DESCrypto.Decryptor(body, key, iv); } catch (Exception ex) { MessageBox.Show("解密失败:" + ex.Message, "错误"); } }
public void TestDecryptor() { var keyValue = DESCrypto.CreatedKey(); string encryptorStr = DESCrypto.Encryptor(input, keyValue.Key, keyValue.Value); String decryptorStr = DESCrypto.Decryptor(encryptorStr, keyValue.Key, keyValue.Value); Assert.IsNotNull(encryptorStr); Assert.IsTrue(encryptorStr.Length > 0); Console.WriteLine(encryptorStr); Assert.IsNotNull(decryptorStr); Assert.IsTrue(decryptorStr.Length > 0); Console.WriteLine(decryptorStr); Assert.IsTrue(decryptorStr.Equals(input)); }