剖析VB.NET MD5加密字符串实现过程

开发 后端
文章主要演示VB.NET MD5加密字符串方法的一个实现,在实现方法中System.Security.Cryptography这个类需要引用,它提供了安全方面的服务,用于MD5只是它的一个毛皮功夫。

网络其实有的时候不是很安全,在传输的过成中可能受到攻击,在这里我为大家讲解 VB.NET MD5加密字符串的实现方法,大家可以试试。

VB.NET MD5加密字符串的实现方法

  1. Imports System.Text  
  2. Imports System.Security.Cryptography  
  3. Public Class Form1Class Form1  
  4. Inherits System.Windows.Forms.Form  
  5. #Region " Windows 窗体设计器生成的代码 "  
  6. Public Sub New()Sub New()  
  7. MyBase.New()  
  8. '该调用是 Windows 窗体设计器所必需的。  
  9. InitializeComponent()  
  10. '在 InitializeComponent() 调用之后添加任何初始化  
  11. End Sub  
  12. '窗体重写 dispose 以清理组件列表。  
  13. Protected Overloads Overrides Sub Dispose()Sub Dispose(ByVal disposing As Boolean)  
  14. If disposing Then  
  15. If Not (components Is Nothing) Then  
  16. components.Dispose()  
  17. End If  
  18. End If  
  19. MyBase.Dispose(disposing)  
  20. End Sub  
  21. 'Windows 窗体设计器所必需的  
  22. Private components As System.ComponentModel.IContainer  
  23. '注意: 以下过程是 Windows 窗体设计器所必需的  
  24. '可以使用 Windows 窗体设计器修改此过程。  
  25. '不要使用代码编辑器修改它。  
  26. Friend WithEvents TextBox1 As System.Windows.Forms.TextBox  
  27. Friend WithEvents TextBox2 As System.Windows.Forms.TextBox  
  28. Friend WithEvents Button1 As System.Windows.Forms.Button  
  29. <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()Sub InitializeComponent()  
  30. Me.TextBox1 = New System.Windows.Forms.TextBox  
  31. Me.TextBox2 = New System.Windows.Forms.TextBox  
  32. Me.Button1 = New System.Windows.Forms.Button  
  33. Me.SuspendLayout()  
  34. '  
  35. 'TextBox1  
  36. '  
  37. Me.TextBox1.Location = New System.Drawing.Point(32, 56)  
  38. Me.TextBox1.Name = "TextBox1" 
  39. Me.TextBox1.Size = New System.Drawing.Size(144, 21)  
  40. Me.TextBox1.TabIndex = 0 
  41. Me.TextBox1.Text = "" 
  42. '  
  43. 'TextBox2  
  44. '  
  45. Me.TextBox2.Location = New System.Drawing.Point(32, 96)  
  46. Me.TextBox2.Name = "TextBox2" 
  47. Me.TextBox2.Size = New System.Drawing.Size(224, 21)  
  48. Me.TextBox2.TabIndex = 1 
  49. Me.TextBox2.Text = "" 
  50. '  
  51. 'Button1  
  52. '  
  53. Me.Button1.Location = New System.Drawing.Point(184, 56)  
  54. Me.Button1.Name = "Button1" 
  55. Me.Button1.TabIndex = 2 
  56. Me.Button1.Text = "Button1" 
  57. '  
  58. 'Form1  
  59. 'Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)  
  60. Me.ClientSize = New System.Drawing.Size(472, 285)  
  61. Me.Controls.Add(Me.Button1)  
  62. Me.Controls.Add(Me.TextBox2)  
  63. Me.Controls.Add(Me.TextBox1)  
  64. Me.Name = "Form1" 
  65. Me.Text = "MD5" 
  66. Me.ResumeLayout(False)  
  67. End Sub  
  68. #End Region  
  69. Private Sub Button1_Click()Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click  
  70. Dim md5 As New MD5CryptoServiceProvider  
  71. Dim username As Byte() = (New ASCIIEncoding).GetBytes(TextBox1.Text)  
  72. '转换为哈希值Byte数组  
  73. Dim mdByte As Byte() = md5.ComputeHash(username)  
  74. 'Dim mdString As String = System.BitConverter.ToString(mdByte)  
  75. Dim mdString As String = (New ASCIIEncoding).GetString(mdByte)  
  76. TextBox2.Text = mdString 
  77. End Sub  
  78. Private Sub Form1_Load()Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load  
  79. End Sub  
  80. End Class 

System.Security.Cryptography这个类需要引用,它提供了安全方面的服务,用于MD5只是它的一个毛皮功夫。以上是有关VB.NET MD5加密字符串的实现方法的一个演示,不是很难吧。

【编辑推荐】

  1. 剖析VB.NET平台调用是如何执行操作
  2. 分享个人总结VB.NET多线程
  3. 详细说明VB.NET变量中四点
  4. 三类十二种VB.NET数据类型全面介绍
  5. VB.NET初步知识,初学者必看
责任编辑:田树 来源: 乐博网
相关推荐

2009-07-28 16:39:16

VB.NET的MD5加

2010-01-11 13:42:20

VB.NET字符串加密

2020-10-15 08:20:52

MD5算法加密的过程

2009-10-16 13:04:57

VB.NET字符串数组

2016-12-15 09:26:53

MD5加密

2010-01-13 15:12:04

VB.NET字符串合并

2009-11-10 12:06:17

VB.NET字符串函数

2010-01-08 15:11:22

VB.NET字符串转义

2009-10-23 13:14:38

2009-06-30 10:05:24

MD5加密JSP源码

2009-10-21 16:00:26

VB.NET CASE

2010-01-18 16:33:57

VB.NET加密文件

2010-01-22 14:59:40

VB.NET表单自动提

2009-11-02 16:22:16

VB.NET面向对象

2022-10-18 22:21:51

2009-10-13 15:09:19

VB.NET使用Tre

2015-03-23 11:21:08

2010-01-14 17:03:01

VB.NET获取网卡地

2009-11-10 13:27:30

VB.NET RND(

2010-01-22 15:37:02

VB.NET监控类
点赞
收藏

51CTO技术栈公众号