如何在 Windows 和 Linux 上加密 Python 中的代码对象
如何将代码对象加密为 base64、字节、sha256 等,但必须同时支持 Windows 和 Linux/Termux。我已经尝试过 marshal.dumps,但它仅适用于制作它的操作系统。就像:我在 Windows 上使用 marshal.dumps
将该代码对象转换为字节。但它只能在 Windows 上运行,当我将该代码移动到 termux/linux 时,它显示Segmentation Failure
。如果我在 linux/termux 上使用相同的方法转换为字节,然后将转换后的代码移至 Windows,它会显示一个对话框,并显示 python 没有响应
。主要代码位于 github 上。这是示例代码:
my_code="print('This is encrypted code')"
enc_code=compile(my_code, 'string', 'exec')
# i want to encrypt this enc_code that supports both windows and linux
编辑:
应该有一个解密方法。我还想解密该代码对象并使用 exec 函数执行它。 例如:
code=compile('print("Sometext")', 'nothing', 'exec')
code.encrypted_value='iurefbiuyrencuigfbc8yoiwusenowrov'
解密该加密值然后执行它:
exec('iurefbiuyrencuigfbc8yoiwusenowrov'.decrypted_code_object)
How to Encrypt a code object to base64, bytes, sha256 etc any of them but that must support both of windows and Linux/Termux. I have tried marshal.dumps
but it only work on that os where it was made. Like: I converted that code object to bytes with marshal.dumps
on windows. But it only runs on windows, when I move that code to termux/linux, it shows Segmentation Fault
. And if I convert to bytes with the same method on linux/termux, and then move that converted code to windows, it shows a dialog box and says python is not responding
. The main code is on github. Here is a sample code:
my_code="print('This is encrypted code')"
enc_code=compile(my_code, 'string', 'exec')
# i want to encrypt this enc_code that supports both windows and linux
Edit:
There should be a decrypt method. I also want to decrypt that code object and execute that with exec function.
Eg:
code=compile('print("Sometext")', 'nothing', 'exec')
code.encrypted_value='iurefbiuyrencuigfbc8yoiwusenowrov'
And decrypt that encrypted value then execute it:
exec('iurefbiuyrencuigfbc8yoiwusenowrov'.decrypted_code_object)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你可以使用密码学库,还没有检查它,但我认为它与linux和windows兼容。
You can use cryptography library, havent checked it but I think it is compatible with both linux and windows.