前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >文本的DES加密 MD5散列值 DSA的数字签名

文本的DES加密 MD5散列值 DSA的数字签名

作者头像
Java架构师必看
发布2020-10-26 11:06:38
7390
发布2020-10-26 11:06:38
举报
文章被收录于专栏:Java架构师必看Java架构师必看

作者:未知文本的DES加密为了对称加密的安全,将密码进行封装,先新建一个用于保存密码的类库cl:usC#

强烈推介IDEA2020.2破解激活,IntelliJ IDEA 注册码,2020.2 IDEA 激活码

作者:未知

文本的DES加密 为了对称加密的安全,将密码进行封装,先新建一个用于保存密码的类库cl: using System; using System.Text ; namespace cl {  /// <summary>  /// Class1 的摘要说明。  /// </summary>  public class Class1  {   public Class1()   {

  }   public string getiv()   {    string iv="********";//八位    return iv;   }   public string getkey()   {    string key="01160129";//八位    return key;   }

 } }

然后新建asp.net项目(C#) 在 .aspx中 using cl; namespace test//给一个文本产生一个散列值 {  /// <summary>  /// computehash 的摘要说明。  /// </summary>  public class computehash : System.Web.UI.Page  {   protected System.Web.UI.WebControls.Label Label1;   protected System.Web.UI.WebControls.TextBox TextBox1;   protected System.Web.UI.WebControls.Button Button1;   protected System.Web.UI.WebControls.TextBox TextBox3;   protected System.Web.UI.WebControls.Button Button2;   protected System.Web.UI.WebControls.TextBox TextBox4;   protected System.Web.UI.WebControls.Button Button3;   protected System.Web.UI.WebControls.TextBox TextBox5;   protected System.Web.UI.WebControls.Button Button4;   protected System.Web.UI.WebControls.Button Button5;   protected System.Web.UI.WebControls.Label Label2;   protected System.Web.UI.WebControls.TextBox TextBox7;   protected System.Web.UI.WebControls.Label Label3;   protected System.Web.UI.WebControls.TextBox TextBox8;   protected System.Web.UI.WebControls.TextBox TextBox9;   protected System.Web.UI.WebControls.Label Label4;   protected System.Web.UI.WebControls.Button Button6;   protected System.Web.UI.WebControls.Label Label5;   protected System.Web.UI.WebControls.TextBox TextBox2;   private void Page_Load(object sender, System.EventArgs e)   {    // 在此处放置用户代码以初始化页面   }

  #region Web 窗体设计器生成的代码   override protected void OnInit(EventArgs e)   {    //    // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。    //    InitializeComponent();    base.OnInit(e);   }   /// <summary>   /// 设计器支持所需的方法 - 不要使用代码编辑器修改   /// 此方法的内容。   /// </summary>   private void InitializeComponent()   {       this.Button2.Click += new System.EventHandler(this.Button2_Click);    this.Button1.Click += new System.EventHandler(this.Button1_Click);    this.Button3.Click += new System.EventHandler(this.Button3_Click);    this.Button4.Click += new System.EventHandler(this.Button4_Click);    this.Button5.Click += new System.EventHandler(this.Button5_Click);    this.Button6.Click += new System.EventHandler(this.Button6_Click);    this.Load += new System.EventHandler(this.Page_Load);

  }   #endregion

  private void Button1_Click(object sender, System.EventArgs e)   {    byte[] bt=UTF8Encoding.UTF8.GetBytes(TextBox1.Text );//UTF8需要对Text的引用             MD5CryptoServiceProvider objMD5;          objMD5=new MD5CryptoServiceProvider ();    byte[] output=objMD5.ComputeHash (bt);    TextBox2.Text =BitConverter.ToString (output);   }

  private void Button2_Click(object sender, System.EventArgs e)   {     byte[] bt=UTF8Encoding.UTF8.GetBytes(TextBox1.Text );//UTF8需要对Text的引用    MD5CryptoServiceProvider objMD5;    objMD5=new MD5CryptoServiceProvider ();    byte[] output=objMD5.ComputeHash (bt);    TextBox4.Text =BitConverter.ToString (output);     }

  private void Button3_Click(object sender, System.EventArgs e)   {    Class1 cl=new Class1 ();    string iv1=cl.getiv ();    string key1=cl.getkey ();

   byte[] iv=UTF8Encoding.UTF8 .GetBytes (iv1);    byte[] key=UTF8Encoding.UTF8 .GetBytes (key1);    byte[] source=UTF8Encoding.UTF8 .GetBytes (TextBox1.Text );    //定义加密对象    DESCryptoServiceProvider objdes;             objdes=new DESCryptoServiceProvider ();    //设置加密对象值    objdes.IV =iv;    objdes.Key =key;    //创建加密器对象    ICryptoTransform objEncryptor;    objEncryptor=objdes.CreateEncryptor (objdes.Key ,objdes.IV );             //准备将加密的文本写入secret.txt中    FileStream objfs;    objfs=new FileStream (MapPath("secret.txt"),FileMode.Create ,FileAccess.Write );             //写入    CryptoStream cryptostream;    cryptostream=new CryptoStream (objfs,objEncryptor,CryptoStreamMode.Write );    cryptostream.Write (source,0,source.Length );    cryptostream.Close ();   }

  private void Button4_Click(object sender, System.EventArgs e)   {    Class1 cl=new Class1 ();    string iv1=cl.getiv ();    string key1=cl.getkey ();    byte[] iv=UTF8Encoding.UTF8 .GetBytes (iv1);    byte[] key=UTF8Encoding.UTF8 .GetBytes (key1);    byte[] source=UTF8Encoding.UTF8 .GetBytes (TextBox1.Text );    //定义加密对象    DESCryptoServiceProvider objdes;    objdes=new DESCryptoServiceProvider ();    //设置加密对象值    objdes.IV =iv;    objdes.Key =key;    //创建加密器对象    ICryptoTransform objEncryptor;    objEncryptor=objdes.CreateEncryptor (objdes.Key ,objdes.IV );    //写到内存    MemoryStream ms=new MemoryStream ();    CryptoStream cs=new CryptoStream (ms,objEncryptor,CryptoStreamMode.Write );    cs.Write (source,0,source.Length );    cs.FlushFinalBlock ();    ms.Close ();    TextBox5.Text =BitConverter.ToString (ms.ToArray ());

  }

  private void Button5_Click(object sender, System.EventArgs e)   {    DSACryptoServiceProvider objdsa;    objdsa=new DSACryptoServiceProvider ();             byte[] source=UTF8Encoding.UTF8 .GetBytes (TextBox1.Text );    //公开秘钥    TextBox8.Text =objdsa.ToXmlString (false);    //私有秘钥    TextBox9.Text =objdsa.ToXmlString (true);    //数字签名    TextBox7.Text =BitConverter.ToString (objdsa.SignData (source));   }

  } }

本文由来源 21aspnet,由 system_mush 整理编辑,其版权均为 21aspnet 所有,文章内容系作者个人观点,不代表 Java架构师必看 对观点赞同或支持。如需转载,请注明文章来源。

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档