C#——设计窗体程序,对输入的两个数做除法运算,抛出合适的异常

1.设计界面:

2.编写代码

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace 两整数相除
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                int x = Convert.ToInt32(textBox1.Text);
                int y = Convert.ToInt

  • 4
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,以下是一个简单的 C# 窗体程序,用 RSA 算法实现对输入的信息进行加密解密的示例代码: ```csharp using System; using System.Windows.Forms; using System.Security.Cryptography; namespace RSA_Encryption { public partial class MainForm : Form { private RSACryptoServiceProvider rsa; public MainForm() { InitializeComponent(); rsa = new RSACryptoServiceProvider(); } // 加密按钮点击事件 private void EncryptButton_Click(object sender, EventArgs e) { byte[] data = System.Text.Encoding.UTF8.GetBytes(InputTextBox.Text); byte[] encryptedData = rsa.Encrypt(data, true); OutputTextBox.Text = Convert.ToBase64String(encryptedData); } // 解密按钮点击事件 private void DecryptButton_Click(object sender, EventArgs e) { byte[] encryptedData = Convert.FromBase64String(InputTextBox.Text); byte[] decryptedData = rsa.Decrypt(encryptedData, true); OutputTextBox.Text = System.Text.Encoding.UTF8.GetString(decryptedData); } } } ``` 代码中,我们使用 `RSACryptoServiceProvider` 类来实现 RSA 算法的加密和解密。在窗体程序的构造函中,我们创建了一个 `RSACryptoServiceProvider` 实例。然后,在加密按钮点击事件中,我们将输入的文本框中的字符串转换为字节组,然后调用 `rsa.Encrypt` 方法进行加密,并将加密结果显示在输出文本框中。在解密按钮点击事件中,我们将输入的文本框中的字符串先解码为字节组,然后调用 `rsa.Decrypt` 方法进行解密,并将解密结果显示在输出文本框中。 需要注意的是,在实际使用 RSA 算法进行加密和解密时,需要使用正确的密钥对,一般来说是使用公钥加密、私钥解密或使用私钥签名、公钥验证。在本示例代码中,我们没有涉及到密钥对的生成和使用,仅仅是使用了 `RSACryptoServiceProvider` 类的默认密钥对。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值