You might need to specify the calling convention for the imported functions,
especially if you intend to use callbacks (-with delegates) in your code, like:
[DllImport("lib\\libeay32.dll" ,CallingConvention=CallingConvention.Cdecl)]
Otherwise, you may get stack imbalance\ memory corruption exceptions (The
default calling convention in dot net is stdcall).
-----Original Message-----
From: [email protected] [mailto:[email protected]]
On Behalf Of Strauch, Robert
Sent: Wednesday, June 23, 2010 3:49 PM
To: '[email protected]'
Subject: Re: Integrating OpenSSL as a DLL in Windows
Here's my sample code.
--- SNIP ---
[DllImport("lib\\libeay32.dll")]
public static extern IntPtr EVP_MD_CTX_create();
[DllImport("lib\\libeay32.dll")]
public static extern IntPtr EVP_md5();
[DllImport("lib\\libeay32.dll")]
public static extern int EVP_DigestInit_ex(IntPtr digestContext, IntPtr
digestType, IntPtr engine);
[DllImport("lib\\libeay32.dll")]
public static extern int EVP_DigestUpdate(IntPtr digestContext, String
messageText, int messageLength);
[DllImport("lib\\libeay32.dll")]
public static extern int EVP_DigestFinal_ex(IntPtr digestContext, IntPtr
digestValue, IntPtr digestLength);
[...]
IntPtr digestContext = new IntPtr();
IntPtr digestType = new IntPtr();
IntPtr digestValue = new IntPtr();
String messageText = "Hello world!";
/* Setup MD5 context */
digestContext = EVP_MD_CTX_create();
digestType = EVP_md5();
/* Context setup successful */
if (EVP_DigestInit_ex(digestContext, digestType, IntPtr.Zero) == 1)
{
/* Perform hashing */
if (EVP_DigestUpdate(digestContext, messageText, messageText.Length) ==
1)
{
/* Hashing successful */
if (EVP_DigestFinal_ex(digestContext, digestValue, IntPtr.Zero)
== 1)
}
else
{
/* Something went wrong */
}
}
else
{
/* Something went wrong */
}
[...]
--- SNIP ---
> Hello,
>
> I've been using OpenSSL for quite a time but now it's time
> for me to integrate some functionality into my own
> application (C#). That is: decrypting with a private key and
> building hashsums. As far as I understood I need the
> libeay32.dll to achieve this. However I cannot find something
> like an API documentiation which describes how to call
> OpenSSL functions from this DLL.
>
> Could someone assist me in this?
>
> Sincerely,
> Robert
>
______________________________________________________________________
OpenSSL Project http://www.openssl.org
User Support Mailing List [email protected]
Automated List Manager [email protected]
---------------------------------------------------------------------
Intel Israel (74) Limited
This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.
______________________________________________________________________
OpenSSL Project http://www.openssl.org
User Support Mailing List [email protected]
Automated List Manager [email protected]