Compiling OpenSSL and OpenSSL.Net for Windows
If you need fast way to hash passwords with MD5/SHA1, or to encrypt and decrypt data with AES I recommend OpenSSL library. This library supports more than 25 algorithms for ciphering, hashing and public-key cryptography. It’s open source and supports most platforms, including Linux, OS X and Windows. To use OpenSSL from C# you need to use a wrapper. I hadn’t had much problems with OpenSSL.Net and it’s supposed to be cross-platform.
Building OpenSSL on Windows
What you need?
- OpenSSL source code http://www.openssl.org/source/
- Perl interpreter http://www.perl.org/get.html
- Visual Studio compiler (should also work with MinGW or similar)
You can build library with assembly optimizations or without them. Optimizations provide faster code execution, according to some benchmarks they can speed up execution by up to 4 times, depending on selected algorithm. To successfully build them you need Visual Studio Professional or better, because VS Express doesn’t offer assembly compiler NASM.
To build x64 version start Visual Studio Command Prompt (x64) and run:
1 2 3 4 | perl Configure VC-WIN64A --prefix=C:\openssl-x64-build ms\do_win64a nmake -f ms\nt.mak nmake -f ms\nt.mak install |
To build x32 version start 32bit Visual Studio CMD and run:
1 2 3 4 | perl Configure VC-WIN32 --prefix=C:\openssl-x32-build ms\do_ms nmake -f ms\nt.mak nmake -f ms\nt.mak install |
If you don’t have assembly compiler add no-asm to perl Configure call (e.g. perl Configure VC-WIN64A no-asm –prefix=C:\openssl-x64-build).
If everything went without a hitch you should find built library in folder specified with –prefix.
Building OpenSSL.Net
What you need?
- Visual Studio or VS Express for C#
- OpenSSL.Net wrapper library http://sourceforge.net/projects/openssl-net/
Download wrapper library and open it with Visual Studio. Choose x32 or x64 platform and press F5. Solution also includes tests (you need NUnit to run them) and example Console application.
The only problem you might have is hard coded version of supported OpenSSL library. Wrapper specifies which version it supports in Core/Native.cs on line 228:
1 | public const uint Wrapper = 0x00908000; |
If you have different version of library you need to modify this value and hope that all calls in library stayed the same.
Alternatively, you can disable consistency check by commenting it in Core/Native.cs on lines 160-166:
1 2 3 4 5 6 | Version lib = Version.Library; Version wrapper = Version.Wrapper; uint mmf = lib.Raw & 0xfffff000; // if (mmf != wrapper.Raw) // throw new Exception(string.Format("Invalid version of {0}, expecting {1}, got: {2}", // DLLNAME, wrapper, lib)); |
After that you shouldn’t have any problems.
Downloads
- OpenSSL 32bit library (built with debug-VC-WIN32 no-asm): openssl.zip
- OpenSSL 64bit library (built with VC-WIN64A and assembly optimizations): openssl64.zip
- OpenSSL.Net 64bit with appropriate OpenSSL library: OpenSSL.Net
Monitoring electricity consumption Compiling programs for OpenWRT