HashForm实现

 

(2)	在命名空间中输入:
using System.IO;
using System.Security.Cryptography;
(3)	在static void Main(string[] args)方法中输入以下代码:
HashAlgorithm  hash=HashAlgorithm.Create();
		Console.WriteLine("Enter a File Name:");
		string fileName=Console.ReadLine();
		FileStream fs=new FileStream(fileName, FileMode.Open);
		byte[] hashBytes=hash.ComputeHash(fs);
		fs.Close();
		//display the hash data
	    Console.Write("Hash:"+BitConverter.ToString(hashBytes));
		    Console.Read();
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
using System.Security.Cryptography;

namespace HashGui
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }


        private void button1_Click(object sender, EventArgs e)
        {
            //textBox1为输入密码的文本框
            byte[] result = Encoding.Default.GetBytes(this.textBox1.Text.Trim());

            /*MD5,SHA256,SHA384,SHA512),及验证码HMACSHA1
             */


            //MD5
            MD5 md5 = new MD5CryptoServiceProvider();
            byte[] output = md5.ComputeHash(result);
            //textBox2为输出加密文本的文本框
            this.textBox2.Text = BitConverter.ToString(output);

            //SHA256
            HashAlgorithm hash256 = HashAlgorithm.Create("SHA256");
            byte[] output256 = hash256.ComputeHash(result);
            this.textBox3.Text = BitConverter.ToString(output256);

            //SHA384
            HashAlgorithm hash384 = HashAlgorithm.Create("SHA384");
            byte[] output384 = hash384.ComputeHash(result);
            this.textBox4.Text = BitConverter.ToString(output384);

            //SHA521
            HashAlgorithm hash512 = HashAlgorithm.Create("SHA512");
            byte[] output512 = hash512.ComputeHash(result);
            this.textBox5.Text = BitConverter.ToString(output512);

            HMACSHA1 myHMACSHA1 = new HMACSHA1();
            byte[] byteText = myHMACSHA1.ComputeHash(result);
            this.textBox6.Text = BitConverter.ToString(output512);

        }

        private void label2_Click(object sender, EventArgs e)
        {

        }
    }
}

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值