python代码没办法加密_用C加密/取消加密Python脚本

这就是我要做的:

1)创建一个生成密钥的C脚本并将其存储到文本文件

2)拿起密钥并在运行Python时立即删除文本文件

3)使用密钥解密Python代码中真正重要的部分(确保没有这些位会破坏脚本),然后全部导入

4)立即重新加密重要的Python位,并删除.pyc文件

这将是可战胜的,但您可以接受.

要加密和重新加密您的python位,请尝试以下代码:

from hashlib import md5

from Crypto.Cipher import AES

from Crypto import Random

def encrypt(in_file, out_file, password, key_length=32):

bs = AES.block_size

salt = Random.new().read(bs - len('Salted__'))

key, iv = derive_key_and_iv(password, salt, key_length, bs)

cipher = AES.new(key, AES.MODE_CBC, iv)

out_file.write('Salted__' + salt)

finished = False

while not finished:

chunk = in_file.read(1024 * bs)

if len(chunk) == 0 or len(chunk) % bs != 0:

padding_length = (bs - len(chunk) % bs) or bs

chunk += padding_length * chr(padding_length)

finished = True

out_file.write(cipher.encrypt(chunk))

def decrypt(in_file, out_file, password, key_length=32):

bs = AES.block_size

salt = in_file.read(bs)[len('Salted__'):]

key, iv = derive_key_and_iv(password, salt, key_length, bs)

cipher = AES.new(key, AES.MODE_CBC, iv)

next_chunk = ''

finished = False

while not finished:

chunk, next_chunk = next_chunk, cipher.decrypt(in_file.read(1024 * bs))

if len(next_chunk) == 0:

padding_length = ord(chunk[-1])

chunk = chunk[:-padding_length]

finished = True

out_file.write(chunk)

总结一下,这是一些伪代码:

def main():

os.system("C_Executable.exe")

with open("key.txt",'r') as f:

key = f.read()

os.remove("key.txt")

#Calls to decrpyt files which look like this:

with open("Encrypted file name"), 'rb') as in_file, open("unecrypted file name"), 'wb') as out_file:

decrypt(in_file, out_file, key)

os.remove("encrypted file name")

import fileA, fileB, fileC, etc

global fileA, fileB, fileC, etc

#Calls to re-encrypt files and remove unencrypted versions along with .pyc files using a similar scheme to decryption calls

#Whatever else you want

但只是强调和重点,

Python不是为此设计的!它的意思是开放和免费的!

如果您在此关头没有其他选择,则可能应该使用其他语言

在 Linux 下安装 PyConcrete 加密 Python 代码的步骤如下: 1. 安装 Python 和 pip PyConcrete 是一个 Python 模块,因此需要安装 Python 和 pip。在 Ubuntu 上,可以使用以下命令安装: ``` sudo apt update sudo apt install python3 python3-pip ``` 2. 安装 PyConcretee 使用 pip 安装 PyConcretee: ``` pip3 install pyconcrete ``` 3. 创建加密脚本 创建一个 Python 脚本,将要加密和保护。例如,我们可以创建一个名为 `my_script.py` 的文件,其中包含以下内容: ``` def my_function(): print("Hello, world!") if __name__ == '__main__': my_function() ``` 4. 创建加密配置文件 创建一个名为 `pyconcrete.cfg` 的文件,并将以下内容添加到其中: ``` [pyconcrete] key = my_secret_key mode = encrypt ``` 其中,`key` 是一个用于加密和解密文件的密钥,`mode` 是指定 PyConcretee 运行模式的选项。在此示例中,我们将使用 `encrypt` 模式加密文件。 5. 加密脚本 使用 PyConcretee 加密脚本: ``` pyconcrete-tool.py encrypt my_script.py -c pyconcrete.cfg -o my_script_encrypted.py ``` 这将使用 `pyconcrete.cfg` 中指定的密钥和模式,将 `my_script.py` 文件加密,并将结果保存到 `my_script_encrypted.py` 文件中。 6. 运行加密脚本 使用 Python 运行加密脚本: ``` python3 my_script_encrypted.py ``` 这将运行已加密的 `my_script_encrypted.py` 文件,并输出 `Hello, world!`。 在以上步骤中,我们使用 PyConcretee 加密了一个 Python 脚本,并在 Linux 上运行了加密后的脚本
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值