OpenSSL-net DllNotFoundException: Assets/Plugins/OpenSSL/libeay32.dll

I am trying to use OpenSSL.net in Unity. I’ve cloned the git repository, build an AnyCPU release built in visual studio which made a directory containing: libeay32.dll, ManagedOpenSsl.dll and ssleay32.dll. I’ve dragged them in my project in Assets\Plugins\OpenSSL and I can now access OpenSSL from script:
using OpenSSL.Crypto;
I’m using a small script to try and use OpenSSL functionality:

byte[] Encrypt(byte[] bytes)
    {
        using (CipherContext cc = new CipherContext(Cipher.AES_256_CBC))
        {
            return cc.Encrypt(bytes, testKey, testIV);
        }
    }

When I run the method, I get an error in the unity console:

*DllNotFoundException: Assets/Plugins/OpenSSL/libeay32.dll
OpenSSL.Core.Version.get_Library ()
OpenSSL.Core.Native…cctor ()
Rethrow as TypeInitializationException: An exception was thrown by the type initializer for OpenSSL.Core.Native
OpenSSL.Crypto.Cipher…cctor ()
Rethrow as TypeInitializationException: An exception was thrown by the type initializer for OpenSSL.Crypto.Cipher
TestSerialization.Update () (at Assets/Scripts/SerializedClasses/TestSerialization.cs:51) *

On line 51, the encrypt method is called. I’m targeting Android and in a later stage IOS but it seems to not even work on Windows 10.

Can someone tell me how this happens?

Kind regards,

Yorick

Solved by switching to this OpenSSL.net repository which is a wrapper written in C# targeting the .NET Framework 3.5.

When you clone the repository(using SourceTree or Tortoise Git or any program of your choice), you will find a folder called native containing Windows dll builds for 32bit and 64bit. Drop the 32bit libeay32.dll and ssleay32.dll in the unity folder: \Assets\Plugins\x86 and drop the 64bit libeay32.dll and ssleay32.dll in \Assets\Plugins\x86_64.

When that’s done open the ManagedOpenSsl-VS2015.sln in Visual Studio (2017). Build the project and navigate to the bin folder which is in the same folder as the .sln. Go in the Debug folder and copy the ManagedOpenSsl.dll and drop it in \Assets\Plugins. You should now be able to access OpenSSL by writing any of these usings:
using OpenSSL;
using OpenSSL.Core;
using OpenSSL.Crypto;
using OpenSSL.Exceptions;
using OpenSSL.Extensions;
using OpenSSL.SSL;
using OpenSSL.X509;
using OpenSSL.Crypto.EC;

Kind regards,

Yorick

if you still get an error saying DllNotFoundException: libeay32 Then you might have to install openSSL from Win32/Win64 OpenSSL Installer for Windows - Shining Light Productions

I also had to add OpenSSL to my paths > Enviroment variables ( “;C:\OpenSSL-Win64\bin”)