Jump to content

vb.net dll always returning function not found from AutoIt


Recommended Posts

Here is my vb .net code. This works from a console application, however this is not working while being called from an AutoIt script using DLLCall. Can someone tell me what I am doing wrong?

Console Application:

Module Module1
Sub Main()
     Dim strEncrypt As String = Decide("Encrypt", "Hello")
     Console.WriteLine("The encrypted value is: " & strEncrypt)
     Console.ReadLine()
     Dim strDecrypt As String = Decide("Decrypt", strEncrypt)
     Console.WriteLine("The decrypted value is: " & strDecrypt)
     Console.ReadLine()
End Sub
End Module

VB.NET DLL Code

Imports System.IO
Imports System.Text
Imports System.Security.Cryptography
Public Class Crypto
Private Shared DES As New TripleDESCryptoServiceProvider
Private Shared MD5 As New MD5CryptoServiceProvider
Private Shared Function MD5Hash(ByVal value As String) As Byte()
     Return MD5.ComputeHash(ASCIIEncoding.ASCII.GetBytes(value))
End Function
Private Shared Function Encrypt(ByVal stringToEncrypt As String, ByVal key As String) As String
     DES.Key = Crypto.MD5Hash(key)
     DES.Mode = CipherMode.ECB
     Dim Buffer As Byte() = ASCIIEncoding.ASCII.GetBytes(stringToEncrypt)
     Return Convert.ToBase64String(DES.CreateEncryptor().TransformFinalBlock(Buffer, 0, Buffer.Length))
End Function
Private Shared Function Decrypt(ByVal encryptedString As String, ByVal key As String) As String
     Try
         DES.Key = Crypto.MD5Hash(key)
         DES.Mode = CipherMode.ECB
         Dim Buffer As Byte() = Convert.FromBase64String(encryptedString)
         Return ASCIIEncoding.ASCII.GetString(DES.CreateDecryptor().TransformFinalBlock(Buffer, 0, Buffer.Length))
     Catch ex As Exception
         'MessageBox.Show("Invalid Key", "Decryption Failed", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
         'Console.WriteLine("Invalid Key - Decryption Failed")
         Return "ERROR"
     End Try
End Function
Public Shared Function Decide(ByVal strEncryptOrDecrypt As String, ByVal strParameter As String) As String
     Dim EncryptionKey As String = "Decryption String Goes Here!"
     If strEncryptOrDecrypt = "Encrypt" Then
         Dim strEncrypted As String = Crypto.Encrypt(strParameter, EncryptionKey)
         Return strEncrypted
     ElseIf strEncryptOrDecrypt = "Decrypt" Then
         Dim strDecrypted As String = Crypto.Decrypt(strParameter, EncryptionKey)
         Return strDecrypted
     Else
         Return "ERROR"
     End If
End Function
End Class

AutoIt code:

$myDll = @ScriptDir & "\Encryption.dll"
$result = DllCall($myDll, "str", "Decide", "str", "Encrypt", "str", "Happy")
MsgBox(0,"@Error", @error)
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...