1414def _encrypt_file (
1515 data : bytes ,
1616 key : bytes ,
17- ) -> None :
17+ ) -> bytes :
1818 return aes_encrypt (data , key )
1919
2020
@@ -44,7 +44,7 @@ def encrypt_key(key: bytes) -> str:
4444 return 'O' .join (map (str , cipher_ls )), numbers ['d' ], numbers ['n' ]
4545
4646
47- def generate_so_file (cipher_key : str , d : int , n : int ):
47+ def generate_so_file (cipher_key : str , d : int , n : int , base_dir : Path = None ):
4848 private_key = f'{ n } O{ d } '
4949 path = Path (os .path .abspath (__file__ )).parent
5050
@@ -62,7 +62,10 @@ def generate_so_file(cipher_key: str, d: int, n: int):
6262 1 ).replace ("__cipher_key = ''" , f"__cipher_key = '{ cipher_key } '" ,
6363 1 ).replace ("from pyencrypt.decrypt import *" , '' )
6464
65- temp_dir = Path (os .getcwd ()) / 'encrypted'
65+ if base_dir is None :
66+ base_dir = Path (os .getcwd ())
67+
68+ temp_dir = base_dir / 'encrypted'
6669 temp_dir .mkdir (exist_ok = True )
6770 loader_file_path = temp_dir / 'loader.py'
6871 loader_file_path .touch (exist_ok = True )
@@ -97,6 +100,7 @@ def generate_so_file(cipher_key: str, d: int, n: int):
97100 encoding = 'utf-8' )
98101 if ret .returncode == 0 :
99102 pass
103+ return True
100104
101105
102106def encrypt_file (path : Path ,
0 commit comments