当前位置:编程学习 > VB >>

vb 中的MD5加密

1。web项目中方法 :

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

System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile("aaaa", "MD5")查看文档方法:

[vb]
Public Shared Function HashPasswordForStoringInConfigFile(ByVal password As String, ByVal passwordFormat As String) As String 
     成员属于: System.Web.Security.FormsAuthentication 
 
摘要: 
 给定标识哈希类型的密码和字符串,该例程产生一个适合存储在配置文件中的哈希密码。   
 
参数: 
password:  要进行哈希运算的密码。  
passwordFormat:  要使用的哈希算法。选项有“sha1”或“md5”。  
 
返回值: 
 返回一个包含哈希密码的 String。 

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的应用程序:

[vb]
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 

 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
 

 

补充:综合编程 , 安全编程 ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,