0

Infos:

  • I have a 32-bit C# (.Net Framework 4.8) application which does Crypto operations and Database operations via ODBC drivers (MSSQL and MySQL). This application will be/is executed on Windows.

  • The target machine will have either MSSQL/MySQL 64-bit ODBC driver

  • Application must be built as 32-bit because it uses 32-bit Crypto APIs (ex: CryptBinaryToString or CryptRetrieveObjectByUrl). These APIs are imported using DLLImport which imports crypt32.dll or cryptnet.dll.

Problem

  • If application is built as 32-bit then I get the "[IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified" error. This happens only in case of MySQL ODBC driver.
  • If application is built as 64-bit then I get the "Arithmetic operation resulted in an overflow." error when Marshal.PtrToStructure is called. Below is the example struct in c# (CRL_ENTRY structure):
        /* C# code */
        [StructLayout(LayoutKind.Sequential)]
        public struct CRL_ENTRY
        {
            public CRYPT_INTEGER_BLOB SerialNumber;
            public FILETIME RevocationDate;
            public Int32 cExtension; //Type DWORD in CPP
            public IntPtr rgExtension; //Type PCERT_EXTENSION in CPP
        }

Attempted the following:

  • Importing 64-bit crypt32.dll or cryptnet.dll (with hardcoded path of SysWOW64). Received "bad image format error".
  • Changing int to System.Int32 so that in 64-bit mode the System.Int32 will be used.

Questions:

  1. Is it possible to import 64-bit crypt32.dll or cryptnet.dll in C#, so that CryptBinaryToString or CryptRetrieveObjectByUrl can be used in 64-bit mode. This would be the best fix in my scenario.
  2. How to force System.IntPtr to be 32-bit even if the application is 64-bit?
  3. Is there a possibility to use 64-Bit MySQL ODBC driver in 32-bit application?

Please note: no third-party libraries are allowed.

mDev
  • 1
  • 1

0 Answers0