Hello guys I am trying to migrate a java code to vb, now I need to duplicate the des encription but I am having trouble with this part.
I admit I havent dont encryption since college.
This encrypt the key using md5, and send it to a fuction for the des encryption, seems I got a clue of the error, the key must be a 8 digit key and I am sending a 16 lenght key.
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)
This is the code that does the encryption
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
The error is when I try to parse the MD5 to the DES.Key
PD: Sorry for my bad english.