vb 中的MD5加密

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


 

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值