Below is the code snippet from vb.net. I want to convert it to python. I used hashlib, hmac and also pyDes but none produced the same result as by the vb program. Any Suggestions.? This is my first time dealing with encryption. Please help me sort this problem.. code:
Imports Microsoft.VisualBasic.CompilerServices
Imports System
Imports System.Diagnostics
Imports System.Security.Cryptography
Imports System.Text
Namespace _Cargo
Public Class Crypto
Private Shared DES As TripleDESCryptoServiceProvider = New TripleDESCryptoServiceProvider()
Private Shared MD5 As MD5CryptoServiceProvider = New MD5CryptoServiceProvider()
<DebuggerNonUserCode()>
Public Sub New()
End Sub
Public Shared Function MD5Hash(value As String) As Byte()
Return Crypto.MD5.ComputeHash(Encoding.ASCII.GetBytes(value))
End Function
Public Shared Function Encrypt(stringToEncrypt As String) As String
Crypto.DES.Key = Crypto.MD5Hash("L6#F&,q2$xLx")
Crypto.DES.Mode = CipherMode.ECB
Dim bytes As Byte() = Encoding.ASCII.GetBytes(stringToEncrypt)
Return Convert.ToBase64String(Crypto.DES.CreateEncryptor().TransformFinalBlock(bytes, 0, bytes.Length))
End Function
Public Shared Function Decrypt(encryptedString As String) As String
Dim result As String
Try
Crypto.DES.Key = Crypto.MD5Hash("L6#F&,q2$xLx")
Crypto.DES.Mode = CipherMode.ECB
Dim array As Byte() = Convert.FromBase64String(encryptedString)
result = Encoding.ASCII.GetString(Crypto.DES.CreateDecryptor().TransformFinalBlock(array, 0, array.Length))
Return result
Catch expr_4D As Exception
ProjectData.SetProjectError(expr_4D)
ProjectData.ClearProjectError()
End Try
result = Nothing
Return result
End Function
End Class
End Namespace