I want to compile an exe with encryption (to prevent "casual" decompiling).
I am able to compile with Pyinstaller v2.1 in one exe file using a spec file, when I don't use encryption.
But, when I add the following line to the .spec file to introduce encryption (pycryptodome ):
block_cipher = pyi_crypto.PyiBlockCipher(key='1234567812345678')
I end up with this error:
File "c:\users\username\test-env\lib\site-packages\Crypto\Util\_raw_api.py", line 151, in c_uint8_ptr
raise TypeError("Object type %s cannot be passed to C code" % type(data))
TypeError: Object type <class 'str'> cannot be passed to C code
The log leading up to the error was:
90328 INFO: Appending 'datas' from .spec
90371 INFO: checking PYZ
90372 INFO: Building PYZ because out00-PYZ.toc is non existent
90373 INFO: Building PYZ (ZlibArchive) C:\Users\choom.000\Documents\masstools_clean\obf\build\graphms\out00-PYZ.pyz
Traceback (most recent call last):
File "C:\Users\choom.000\test-env\Scripts\pyinstaller-script.py", line 11, in <module>
load_entry_point('PyInstaller==3.3.1', 'console_scripts', 'pyinstaller')()
File "c:\users\choom.000\test-env\lib\site-packages\PyInstaller\__main__.py", line 94, in run
run_build(pyi_config, spec_file, **vars(args))
File "c:\users\choom.000\test-env\lib\site-packages\PyInstaller\__main__.py", line 46, in run_build
PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
File "c:\users\choom.000\test-env\lib\site-packages\PyInstaller\building\build_main.py", line 791, in main
build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build'))
File "c:\users\choom.000\test-env\lib\site-packages\PyInstaller\building\build_main.py", line 737, in build
exec(text, spec_namespace)
File "<string>", line 20, in <module>
File "c:\users\choom.000\test-env\lib\site-packages\PyInstaller\building\api.py", line 98, in __init__
self.__postinit__()
File "c:\users\choom.000\test-env\lib\site-packages\PyInstaller\building\datastruct.py", line 161, in __postinit__
self.assemble()
File "c:\users\choom.000\test-env\lib\site-packages\PyInstaller\building\api.py", line 133, in assemble
pyz = ZlibArchiveWriter(self.name, toc, code_dict=self.code_dict, cipher=self.cipher)
File "c:\users\choom.000\test-env\lib\site-packages\PyInstaller\archive\writers.py", line 184, in __init__
super(ZlibArchiveWriter, self).__init__(archive_path, logical_toc)
File "c:\users\choom.000\test-env\lib\site-packages\PyInstaller\archive\writers.py", line 59, in __init__
self._add_from_table_of_contents(logical_toc)
File "c:\users\choom.000\test-env\lib\site-packages\PyInstaller\archive\writers.py", line 84, in _add_from_table_of_contents
self.add(toc_entry) # The guts of the archive.
File "c:\users\choom.000\test-env\lib\site-packages\PyInstaller\archive\writers.py", line 213, in add
obj = self.cipher.encrypt(obj)
File "c:\users\choom.000\test-env\lib\site-packages\PyInstaller\archive\pyz_crypto.py", line 58, in encrypt
return iv + self.__create_cipher(iv).encrypt(data)
File "c:\users\choom.000\test-env\lib\site-packages\PyInstaller\archive\pyz_crypto.py", line 64, in __create_cipher
return self._aesmod.new(self.key, self._aesmod.MODE_CFB, iv)
File "c:\users\choom.000\test-env\lib\site-packages\Crypto\Cipher\AES.py", line 200, in new
return _create_cipher(sys.modules[__name__], key, mode, *args, **kwargs)
File "c:\users\choom.000\test-env\lib\site-packages\Crypto\Cipher\__init__.py", line 55, in _create_cipher
return modes[mode](factory, **kwargs)
File "c:\users\choom.000\test-env\lib\site-packages\Crypto\Cipher\_mode_cfb.py", line 230, in _create_cfb_cipher
cipher_state = factory._create_base_cipher(kwargs)
File "c:\users\choom.000\test-env\lib\site-packages\Crypto\Cipher\AES.py", line 100, in _create_base_cipher
result = start_operation(c_uint8_ptr(key),
File "c:\users\choom.000\test-env\lib\site-packages\Crypto\Util\_raw_api.py", line 151, in c_uint8_ptr
raise TypeError("Object type %s cannot be passed to C code" % type(data))
TypeError: Object type <class 'str'> cannot be passed to C code
Seems like it is a problem with the "key" which is class 'str'. I tried to change in the .spec file the key = 'a123456712345678' or u'1234567812345678' but still have the problem.