Importing SSL dll into project

2.8k views Asked by At

I have a project which I imported from old system. This code became most problematic

PacketGroup = new ArrayList();
Crypto = new GameCrypto(ASCIIEncoding.ASCII.GetBytes(STRING_CRYPTO));
KeyExchance = new OpenSSL.Crypto.DH();
KeyExchance.G = RANDOM_INT;
KeyExchance.P = OpenSSL.Core.BigNumber.FromHexString("KEY__KEY_KEY\0");
KeyExchance.GenerateKeys();
NewServerIV = GenerateIV();
NewClientIV = GenerateIV();

At first I received the error:

System.TypeInitializationException: The type initializer for 'OpenSSL.Native' th rew an exception. ---> System.Exception: Invalid version of libeay32.dll, expect ing 0.9.8a Development, got: 1.0.0 Release

I imported the latest SSL library in the project and got this error (on the line on the line Crypto = new GameCrypto())

System.DllNotFoundException: Unable to load DLL 'libeay32.dll': The application has failed to start because its side-by-side configuration is incorrect. Please see the application event log or use the command-line sxstrace.exe tool for more detail. (Exception from HRESULT: 0x800736B1)

at PROJECT_NAME.Native.BF_set_key(IntPtr _key, Int32 len, Byte[] data) at PROJECT_NAME.Main.Blowfish.SetKey(Byte[] data) in PATH\Main\Blowfish.cs:line 85 at PROJECT_NAME.Main.GameCrypto..ctor(Byte[] key) in PATH\Main\Blowfish.cs:line 15 at PROJECT_NAME.Main.GameClient..ctor(Boolean Robot) in PATH\Main\GameClient.cs:line 48

I was able to resolve this problem and I got stuck on this problem (on the line new OpenSSL.Crypto.DH())

System.TypeInitializationException: The type initializer for 'OpenSSL.Core.Native' threw an exception. ---> System.DllNotFoundException: Unable to load DLL 'ssleay32': The operating system cannot run . (Exception from HRESULT: 0x800700B6)

at OpenSSL.Core.Native.SSL_library_init() at OpenSSL.Core.Native..cctor() --- End of inner exception stack trace --- at OpenSSL.Core.Native.DH_new() at OpenSSL.Crypto.DH..ctor() at PROJECT_NAME.Main.GameClient..ctor(Boolean Robot) in PATH\Main\GameClient.cs:line 49 System.NullReferenceException: Object reference not set to an instance of an object. at PROJECT_NAME.Main.GameWorker.ConnectionHandler(StateObj S) in PATH\Main\GameWorker.cs:line 33

1

There are 1 answers

0
TheGeneral On BEST ANSWER

You need a copy of libeay32.dll, libssl32.dll and ssleay32.dll in your application directory

  1. Add the unmanaged dll as a file or linked file in your project. (right click project -> add -> existing file then either Add or Add as Link).

  2. Select the file in the solution explorer. In the properties window set build action to copy always.

Don't forget that the unmanaged DLL could itself require other unmanaged DLL's. If you forget to add those as well, you could get the exact same error. You can use dependency walker to help you if you are not sure what the dependencies are.