c# - 将 SSL dll 导入项目

标签 c# c++ .net ssl visual-studio-project

我有一个从旧系统导入的项目。 这段代码成为最有问题的

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();

起初我收到错误:

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

我在项目中导入了最新的SSL库,出现了这个错误(在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

我能够解决这个问题,但我被困在这个问题上(在 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

最佳答案

您的应用程序目录中需要一份 libeay32.dlllibssl32.dllssleay32.dll

  1. 将非托管 dll 作为文件或链接文件添加到您的项目中。 (右键单击项目 -> 添加 -> 现有文件,然后添加或添加为链接)。

  2. 在解决方案资源管理器中选择文件。在属性窗口中将构建操作设置为始终复制。

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.

关于c# - 将 SSL dll 导入项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27629684/

相关文章:

c++ - 从灵气中制作共享指针的 vector

.net - 使用 Clickonce 部署 Microsoft.Bcl.Async

c# - 如何存储 WPF 应用程序的登录信息

C# XML X文档

c# - 泛型中的多态性

c# - 将 curl 与 Phalanger 结合使用

c++ - 使用重载下标运算符 “[ ]” 获取和设置数组的值将不起作用

c# - 如何更新多个部分 View (一个主网格和另一个总计网格)?

c++ - C++:我没有得到正确的输出(菜鸟问题)

.net - 如何防止 DbContext 更改数据库?