加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

vb 中的MD5加密

发布时间:2020-12-17 08:17:08 所属栏目:百科 来源:网络整理
导读:1。web项目中方法 : System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile("aaaa","MD5") 查看文档方法: Public Shared Function HashPasswordForStoringInConfigFile(ByVal password As String,ByVal passwordFormat As String)

1。web项目中方法 :

System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile("aaaa","MD5")

查看文档方法:

Public Shared Function HashPasswordForStoringInConfigFile(ByVal password As String,ByVal passwordFormat As String) As String
     成员属于: System.Web.Security.FormsAuthentication

摘要:
 给定标识哈希类型的密码和字符串,该例程产生一个适合存储在配置文件中的哈希密码。  

参数:
password:  要进行哈希运算的密码。 
passwordFormat:  要使用的哈希算法。选项有“sha1”或“md5”。 

返回值:
 返回一个包含哈希密码的 String。


2。vb的应用程序:

  Private Function md5()
    Dim tmpSource() As Byte
    Dim tmpHash() As Byte
    tmpSource = ASCIIEncoding.ASCII.GetBytes("aaaa") ' 将指定的 System.String 编码为字节数组。 ASCII(7 位)字符集的编码
    tmpHash = New MD5CryptoServiceProvider().ComputeHash(tmpSource) ' 计算指定字节数组的哈希值。 
    Dim i As Integer
    Dim sOutput As New StringBuilder(tmpHash.Length)
    For i = 0 To tmpHash.Length - 1
      sOutput.Append(tmpHash(i).ToString("x2"))
      'ToString:使用指定格式将此实例的数值转换为它的等效字符串值
      'x2:转为2位16进制小写 ,X2就是转为2位16进制大写
    Next
  End Function
 Public Shared Function md5str(ByRef strSource As String)
        Dim dataToHash As Byte() = (New System.Text.UnicodeEncoding).GetBytes(strSource.ToCharArray)
        Dim hashvalue As Byte() = CType(Cryptography.CryptoConfig.CreateFromName("MD5"),Cryptography.HashAlgorithm).ComputeHash(dataToHash)
        Dim strSB As New System.Text.StringBuilder
        For i As Int16 = 0 To hashvalue.Length - 1
            strSB.Append(hashvalue(i).ToString("x2"))
        Next
        Dim creatMD5 = strSB.ToString
        Return creatMD5

    End Function

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读