【发布时间】:2019-08-08 17:55:13
【问题描述】:
这个脚本是异或加密功能,如果加密小文件就好了,但是我试过打开加密一个大文件(大约5GB)的错误信息:
“溢出错误:大小不适合 int” ,而且打开太慢了。
谁能帮我优化我的脚本,谢谢。
from Crypto.Cipher import XOR
import base64
import os
def encrypt():
enpath = "D:\\Software"
key = 'vinson'
for files in os.listdir(enpath):
os.chdir(enpath)
with open(files,'rb') as r:
print ("open success",files)
data = r.read()
print ("loading success",files)
r.close()
cipher = XOR.new(key)
encoding = base64.b64encode(cipher.encrypt(data))
with open(files,'wb+') as n:
n.write(encoding)
n.close()
【问题讨论】:
-
不要调用
XOR加密。充其量只是混淆。 -
除了密码选择之外,您还需要以密码块大小的倍数从源文件中读取数据,然后在循环中将加密块写回。
标签: python encryption pycrypto