ThalesGroup / pycryptoki

Python interface to SafeNet's PKCS11 library implementation
Apache License 2.0
59 stars 22 forks source link

How to build this project to use the 32bit library instead of 64? #48

Open mlaw-swi opened 8 months ago

mlaw-swi commented 8 months ago

I am wondering if there's a way to use the win32/cryptoki.dll instead of the 64bit cryptoki.dll by default.

astraw38 commented 8 months ago

If you're using 32b python, it should automatically use the 32b library referenced in the crystoki config files (LibUNIX in Chrystoki.conf for linux, LibNT in crystoki.ini for windows).

Alternatively, set the CRYSTOKI_CONF_DLL environment variable to point directly to your dll/.so path.

mlaw-swi commented 8 months ago

Hi @astraw38, I've tried using 32b python and I am using the win32/cryptoki.dll by changing the cryptoki.ini. I still get this error. Traceback (most recent call last): File "C:\repo\github\pycryptoki\test.py", line 55, in c_initialize_ex() File "C:\repo\github\pycryptoki\pycryptoki\exceptions.py", line 61, in luna_function_exception_handle return_tuple = luna_function(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\repo\github\pycryptoki\pycryptoki\session_management.py", line 83, in c_initialize ret = C_Initialize(init_struct_p) ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\repo\github\pycryptoki\pycryptoki\cryptoki\helpers.py", line 248, in luna_function late_binded_function = getattr(CryptokiDLLSingleton().get_dll(), function_name) ^^^^^^^^^^^^^^^^^^^^^^ File "C:\repo\github\pycryptoki\pycryptoki\cryptoki\helpers.py", line 196, in new new_instance.loaded_dll_library = CDLL(dll_path) ^^^^^^^^^^^^^^ File "C:\Users\mlaw\AppData\Local\anaconda3\Lib\ctypes__init.py", line 376, in init__ self._handle = _dlopen(self._name, mode) ^^^^^^^^^^^^^^^^^^^^^^^^^ OSError: [WinError 193] %1 is not a valid Win32 application

astraw38 commented 8 months ago

You'd need to use 32b python to load the 32b dll (ref)