From caeab37fbdd24b717e59a97189e8e9d3a6b83cd3 Mon Sep 17 00:00:00 2001 From: Ivan Maslov Date: Sat, 22 Feb 2020 09:51:31 +0300 Subject: [PATCH] #Tool.SafeSource prototype (Crypt/Decrypt) --- Sources/pyOpenRPA/Tools/SafeSource/Crypter.py | 64 +++++++++ .../pyOpenRPA/Tools/SafeSource/DistrCreate.py | 28 ++++ .../pyOpenRPA/Tools/SafeSource/DistrRun.py | 135 ++++++++++++++++++ .../pyOpenRPA/Tools/SafeSource/__init__.py | 0 .../pyOpenRPA/Tools/SafeSource/__main__.py | 21 +++ Utils/SafeSource/DistrCreate_x64.cmd | 4 + Utils/SafeSource/DistrRun_x64.cmd | 4 + 7 files changed, 256 insertions(+) create mode 100644 Sources/pyOpenRPA/Tools/SafeSource/Crypter.py create mode 100644 Sources/pyOpenRPA/Tools/SafeSource/DistrCreate.py create mode 100644 Sources/pyOpenRPA/Tools/SafeSource/DistrRun.py create mode 100644 Sources/pyOpenRPA/Tools/SafeSource/__init__.py create mode 100644 Sources/pyOpenRPA/Tools/SafeSource/__main__.py create mode 100644 Utils/SafeSource/DistrCreate_x64.cmd create mode 100644 Utils/SafeSource/DistrRun_x64.cmd diff --git a/Sources/pyOpenRPA/Tools/SafeSource/Crypter.py b/Sources/pyOpenRPA/Tools/SafeSource/Crypter.py new file mode 100644 index 00000000..62705ef2 --- /dev/null +++ b/Sources/pyOpenRPA/Tools/SafeSource/Crypter.py @@ -0,0 +1,64 @@ +import os, random, struct +from Crypto.Cipher import AES + +def encrypt_file(key, in_filename, out_filename=None, chunksize=64*1024): + """ Шифрует файл используя AES (режим CBC) с + заданным ключом. + + key: + Ключ шифрования - строка длиной + 16, 24 или 32 байта. Более длинные ключи + более безопасны. + + in_filename: + Имя входного файла + + out_filename: + Если None, будет использоваться « .enc». + + chunksize: + Устанавливает размер фрагмента, который функция + использует для чтения и шифрования файла.Большие + размеры могут быть быстрее для некоторых файлов и машин. + кусок (chunk) должен делиться на 16. + """ + if not out_filename: + out_filename = in_filename + '.enc' + iv = ''.join(chr(random.randint(0, 0xFF)) for i in range(16)) + iv = iv.encode('utf8')[0:16] + encryptor = AES.new(key, AES.MODE_CBC, iv) + filesize = os.path.getsize(in_filename) + with open(in_filename, 'rb') as infile: + with open(out_filename, 'wb') as outfile: + outfile.write(struct.pack('nul \ No newline at end of file diff --git a/Utils/SafeSource/DistrRun_x64.cmd b/Utils/SafeSource/DistrRun_x64.cmd new file mode 100644 index 00000000..0fc026df --- /dev/null +++ b/Utils/SafeSource/DistrRun_x64.cmd @@ -0,0 +1,4 @@ +cd %~dp0..\..\Sources +copy /Y ..\Resources\WPy64-3720\python-3.7.2.amd64\python.exe ..\Resources\WPy64-3720\python-3.7.2.amd64\OpenRPA_SafeSource.exe +..\Resources\WPy64-3720\python-3.7.2.amd64\OpenRPA_SafeSource.exe -m pyOpenRPA.Tools.SafeSource "Run" +pause >nul \ No newline at end of file