大家好我正在嘗試將Java代碼遷移到VB,現在我需要複製DES加密,但我在這部分中遇到了問題。VB,DES和MD5
我承認我從大學以來就沒有加密過。
這使用MD5加密密鑰,並將其發送到DES加密函數,似乎我得到了錯誤的線索,密鑰必須是8位密鑰,我發送16長度密鑰。
Dim MD5 As New MD5CryptoServiceProvider()
Dim dataHash() As Byte = MD5.ComputeHash(Encoding.UTF8.GetBytes(challenge + password))
Dim sb As New StringBuilder
Dim b As Byte
For Each b In dataHash
sb.Append(b.ToString("x2").ToLower())
Next
Dim md5Key As String = sb.ToString
''Dim md5Key As String = digestUtils.md5Hex(challenge + password)
Dim geoEncrypt As New GeoEncriptamiento
Dim challengeAnswer As String = geoEncrypt.EncryptFile(challenge, md5Key)
這是做加密
Function EncryptFile(ByVal esquema As String, ByVal llave As String) As String
Dim DES As New DESCryptoServiceProvider()
'Establecer la clave secreta para el algoritmo DES.
'Se necesita una clave de 64 bits y IV para este proveedor
DES.Key = UTF8Encoding.UTF8.GetBytes(llave)
DES.IV = UTF8Encoding.UTF8.GetBytes(llave)
Try
Dim inputByteArray() As Byte = Encoding.UTF8.GetBytes(esquema)
Dim ms As New MemoryStream
Dim cs As New CryptoStream(MS, DES.CreateEncryptor(DES.Key, DES.IV), CryptoStreamMode.Write)
cs.Write(inputByteArray, 0, inputByteArray.Length)
cs.FlushFinalBlock()
Return Convert.ToBase64String(ms.ToArray())
Catch ex As Exception
Return "Error"
End Try
End Function
代碼的錯誤是,當我嘗試了MD5解析到DES.Key
雖然我與你的主張一致,Java方法返回一個十六進制哈希 昏暗md5Key的String = digestUtils.md5Hex(挑戰+密碼) 這就是爲什麼我不能使用其他哈希方法,但感謝您的重播。 – Enrique 2010-10-07 21:33:44