No way it will covert in the time I have available - it's part of a larger C based application, and it's not well written (in my opinion). Also, I'm a C++ noob, so there's no way I've got the skills yet to do a job like that in a short space of time. Trying to compile with the c++ compiler gives a couple of hundred errors.
I guess I need to re-think this - I wanted to keep the C application as is, apart from a call to my external c++ DLL, but it looks like I'll have to get into the C code and accomplish what I need there.
For the moment a trivial XOR encryption will suffice, and over the weekend I'll try to implement libtomcrypt with the application.
Is there an easy to use C based encryption library you would recommend, as an alternative to libtomcrypt?
It's part of a in-house ERP package, used for controlling the packing out of active ingredient for a pharmaceutical plant. Really needs to be replaced with something more modern and maintainable, and more in line with FDA guidelines for such systems.
The guy who usually worked on it got his ass fired on Monday, so I got lumped with it :(
Thanks a million for taking the time to help with this - I'll check out openssl over the weekend.
int write_msg(char* pszMsg);
} // extern "C"
The properties of the .cpp file need to be altered so that the /clr compiler flag is used for this file. Note it means you have to adjust some of the other default flags (e.g. /ZI -> /Zi, for the debug build)
1 2 3 4 5 6 7 8 9 10 11 12 13
// net_shim.cpp (built with /clr compiler flag, so it
// supports managed code)
int write_msg(char* pszMsg)
String^ msg = gcnew String(pszMsg);
Hello, .Net world
Whether this approach is better or not, than swapping to an alternative cryptographic library, depends on the data types you need to pass to the .Net functions (i.e. how much work there is to marshall the data)
This is perfect - now I can encapsulate the code changes in a C++ program and use the System::Security::Cryptography library for my task. Minimum changes will then be required to the original C code, which is exactly what I needed.
Thank you both for your efforts and your time - you have really saved my bacon this week!! I hope I get the opportunity to repay the favour in the future!
Now I have to write a mountain of documentation for the validation team!#
But I only did it to remind myself how to use COM from C (not something I'd do by choice!)
PS To get the .h and _i.c you've got to open the .tlb file generated by regasm.exe with OLE-COM Object Viewer and export (Save As) the .h, .c, and .idl (This didn't work for me: the idl file ws truncated. So I cut and paste the .idl from the viewer's windows and then ran midl on it:
midl /Oicf sManagedDLL.IDL /h sManagedDLL.h
Then copied the files where I needed them.
PPS This knowledgebase article does seem to be long in the tooth. Even with VC++2008 I had to make tweaks (inc. the inconsistent name of the managed DLL -- sManagedDLL vs ManagedDLL).