1个回答
展开全部
注意参数,Text是密文。sKey是你的加密干扰符
Public Shared Function Decrypt(ByVal Text As String, ByVal sKey As String) As String
Dim provider As New DESCryptoServiceProvider()
Dim num As Integer = Text.Length \ 2
Dim buffer As Byte() = New Byte(num - 1) {}
For i As Integer = 0 To num - 1
Dim num3 As Integer = Convert.ToInt32(Text.Substring(i * 2, 2), &H10)
buffer(i) = CByte(num3)
Next
provider.Key = Encoding.ASCII.GetBytes(FormsAuthentication.HashPasswordForStoringInConfigFile(sKey, "md5").Substring(0, 8))
provider.IV = Encoding.ASCII.GetBytes(FormsAuthentication.HashPasswordForStoringInConfigFile(sKey, "md5").Substring(0, 8))
Dim stream As New MemoryStream()
Dim stream2 As New CryptoStream(stream, provider.CreateDecryptor(), CryptoStreamMode.Write)
stream2.Write(buffer, 0, buffer.Length)
stream2.FlushFinalBlock()
Return Encoding.[Default].GetString(stream.ToArray())
End Function
Public Shared Function Decrypt(ByVal Text As String, ByVal sKey As String) As String
Dim provider As New DESCryptoServiceProvider()
Dim num As Integer = Text.Length \ 2
Dim buffer As Byte() = New Byte(num - 1) {}
For i As Integer = 0 To num - 1
Dim num3 As Integer = Convert.ToInt32(Text.Substring(i * 2, 2), &H10)
buffer(i) = CByte(num3)
Next
provider.Key = Encoding.ASCII.GetBytes(FormsAuthentication.HashPasswordForStoringInConfigFile(sKey, "md5").Substring(0, 8))
provider.IV = Encoding.ASCII.GetBytes(FormsAuthentication.HashPasswordForStoringInConfigFile(sKey, "md5").Substring(0, 8))
Dim stream As New MemoryStream()
Dim stream2 As New CryptoStream(stream, provider.CreateDecryptor(), CryptoStreamMode.Write)
stream2.Write(buffer, 0, buffer.Length)
stream2.FlushFinalBlock()
Return Encoding.[Default].GetString(stream.ToArray())
End Function
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询