写了个爬虫爬取了最新的银行联行号数据库大约12万行数据保存为csv,又用python的pandas模块写了个离线查询工具,方便自己也方便同事,然而csv和xlsx的读取速度实在不敢恭维,转为txt后几乎秒读。为了避免txt明文被善意修改影响正常使用被迫加密…
代码如下(仅加密解密部分):
#!/usr/bin/env python
#AES-demo
import base64
from Crypto.Cipher import AES
‘’’
采用AES对称加密算法
‘’’
str不是16的倍数那就补足为16的倍数
def add_to_16(value):
while len(value) % 16 != 0:
value += ‘\0’
return str.encode(value) # 返回bytes
加密方法
def encrypt_oracle():
# 秘钥
key = ‘33818121’
# 一次性读取文本内容
with open(‘banks.txt’, ‘r’, encoding=‘utf-8’) as banks:
# print(text) 测试打印读取的数据
# 待加密文本
mystr = banks.read()
text = base64.b64encode(mystr.encode(‘utf-8’)).decode(‘ascii’)
# 初始化加密器
aes = AES.new(add_to_16(key), AES.MODE_ECB)
# 先进行aes加密
encrypt_aes = aes.encrypt(add_to_16(text))
# 用base64转成字符串形式
encrypted_text = str(base64.encodebytes(encrypt_aes), encoding=‘utf-8’) # 执行加密并转码返回bytes
# print(encrypted_text) 测试打印加密数据
# 写入加密数据到文件
with open(“bankdata.txt”,“w”) as bankdata:
bankdata.write(encrypted_text)
解密方法
def decrypt_oralce():
# 秘钥
key = ‘33818121’
# 密文
with open(‘bankdata.txt’, ‘r’, encoding=‘utf-8’) as banks:
# print(text) 测试打印读取的加密数据
# 待解密文本
text = banks.read()
# 初始化加密器
aes = AES.new(add_to_16(key), AES.MODE_ECB)
# 优先逆向解密base64成bytes
base64_decrypted = base64.decodebytes(text.encode(encoding=‘utf-8’))
# bytes解密
decrypted_text = str(aes.decrypt(base64_decrypted),encoding=‘utf-8’) # 执行解密密并转码返回str
decrypted_text = base64.b64decode(decrypted_text.encode(‘utf-8’)).decode(‘utf-8’)
print(decrypted_text)
if name == ‘main’:
encrypt_oracle()
decrypt_oralce()
加密数据截图
jia2.png
解密数据截图
jia.png
http://www.gzslpzx.com/poser.php?913199.html
http://nd.fjmj.org.cn/uploadfile/2020/poser.php?913199.html
http://sz.fjmj.org.cn/uploadfile/2020/poser.php?913199.html
http://na.fjmj.org.cn/uploadfile/2020/poser.php?913199.html
http://zz.fjmj.org.cn/uploadfile/2020/poser.php?913199.html
http://np.fjmj.org.cn/uploadfile/2020/poser.php?913199.html
http://mdzz.itlun.cn/poser.php?913199.html
http://www.xalsh.com/poser.php?913199.html
http://www.gjtuofa.com/uploads/poser.php?913199.html
http://www.yqyy.net/poser.php?913199.html
http://www.bxysg.com/poser.asp?913199.html
http://www.linkcard.cn/poser.asp?913199.html
http://www.airber.com.cn/poser.asp?913199.html
http://www.milient.com/poser.asp?913199.html
http://www.moswe.com/poser.asp?913199.html
http://1798.rongbiz.net/poser.php?913199.html
http://bbs.6y.com.cn/poser.php?913199.html
http://game.6y.com.cn/poser.php?913199.html
http://www.hnalizs.com/poser.php?913199.html
http://www.hnhcnet.com/poser.php?913199.html
http://dxkj.designboom.cn/poser.php?913199.html
http://www.designboom.cn/poser.php?913199.html
http://www.zhjswhw.com/poser.php?913199.html
http://www.gdnhec.com/poser.php?913199.html
http://www.qqql.com.cn/poser.asp?913199.html
http://www.ogood.cn/poser.php?913199.html
http://www.lygwb.com/poser.php?913199.html
http://mzhihui.mulangcm.com/fw/poser.php?913199.html
http://www.ceht.com.cn/default.php?913199.html
http://www.aselock.com.cn/poser.asp?913199.html
http://www.spark-lock.com/poser.asp?913199.html
http://www.fsruijian.net/poser.php?913199.html
http://www.whbts.com/poser.asp?913199.html
http://www.xdmonitor.com/poser.asp?913199.html
http://m.cquedp.com/913199.html
http://cquedp.com/913199.html
http://mdzz.itlun.cn/913199.html
http://m.cntricycle.com/913199.html
http://www.cquedp.com/poser.php?913199.html
http://szgc.glodon.com/poser.php?913199.html
http://sz.glodon.com/poser.php?913199.html
http://www.gzslpzx.com/poser.php?317931.html
http://nd.fjmj.org.cn/uploadfile/2020/poser.php?317931.html
http://sz.fjmj.org.cn/uploadfile/2020/poser.php?317931.html
http://na.fjmj.org.cn/uploadfile/2020/poser.php?317931.html
http://zz.fjmj.org.cn/uploadfile/2020/poser.php?317931.html
http://np.fjmj.org.cn/uploadfile/2020/poser.php?317931.html
http://mdzz.itlun.cn/poser.php?317931.html
http://www.xalsh.com/poser.php?317931.html
http://www.gjtuofa.com/uploads/poser.php?317931.html
http://www.yqyy.net/poser.php?317931.html
http://www.bxysg.com/poser.asp?317931.html
http://www.linkcard.cn/poser.asp?317931.html
http://www.airber.com.cn/poser.asp?317931.html
http://www.milient.com/poser.asp?317931.html
http://www.moswe.com/poser.asp?317931.html
http://1798.rongbiz.net/poser.php?317931.html
http://bbs.6y.com.cn/poser.php?317931.html
http://game.6y.com.cn/poser.php?317931.html
http://www.hnalizs.com/poser.php?317931.html
http://www.hnhcnet.com/poser.php?317931.html
http://dxkj.designboom.cn/poser.php?317931.html
http://www.designboom.cn/poser.php?317931.html
http://www.zhjswhw.com/poser.php?317931.html
http://www.gdnhec.com/poser.php?317931.html
http://www.qqql.com.cn/poser.asp?317931.html
http://www.ogood.cn/poser.php?317931.html
http://www.lygwb.com/poser.php?317931.html
http://mzhihui.mulangcm.com/fw/poser.php?317931.html
http://www.ceht.com.cn/default.php?317931.html
http://www.aselock.com.cn/poser.asp?317931.html
http://www.spark-lock.com/poser.asp?317931.html
http://www.fsruijian.net/poser.php?317931.html
http://www.whbts.com/poser.asp?317931.html
http://www.xdmonitor.com/poser.asp?317931.html
http://m.cquedp.com/317931.html
http://cquedp.com/317931.html
http://mdzz.itlun.cn/317931.html
http://m.cntricycle.com/317931.html
http://www.cquedp.com/poser.php?317931.html
http://szgc.glodon.com/poser.php?317931.html
http://sz.glodon.com/poser.php?317931.html
http://www.gzslpzx.com/poser.php?953535.html
http://nd.fjmj.org.cn/uploadfile/2020/poser.php?953535.html
http://sz.fjmj.org.cn/uploadfile/2020/poser.php?953535.html
http://na.fjmj.org.cn/uploadfile/2020/poser.php?953535.html
http://zz.fjmj.org.cn/uploadfile/2020/poser.php?953535.html
http://np.fjmj.org.cn/uploadfile/2020/poser.php?953535.html
http://mdzz.itlun.cn/poser.php?953535.html
http://www.xalsh.com/poser.php?953535.html
http://www.gjtuofa.com/uploads/poser.php?953535.html
http://www.yqyy.net/poser.php?953535.html
http://www.bxysg.com/poser.asp?953535.html
http://www.linkcard.cn/poser.asp?953535.html
http://www.airber.com.cn/poser.asp?953535.html
http://www.milient.com/poser.asp?953535.html
http://www.moswe.com/poser.asp?953535.html
http://1798.rongbiz.net/poser.php?953535.html
http://bbs.6y.com.cn/poser.php?953535.html
http://game.6y.com.cn/poser.php?953535.html
http://www.hnalizs.com/poser.php?953535.html
http://www.hnhcnet.com/poser.php?953535.html
http://dxkj.designboom.cn/poser.php?953535.html
http://www.designboom.cn/poser.php?953535.html
http://www.zhjswhw.com/poser.php?953535.html
http://www.gdnhec.com/poser.php?953535.html
http://www.qqql.com.cn/poser.asp?953535.html
http://www.ogood.cn/poser.php?953535.html
http://www.lygwb.com/poser.php?953535.html
http://mzhihui.mulangcm.com/fw/poser.php?953535.html
http://www.ceht.com.cn/default.php?953535.html
http://www.aselock.com.cn/poser.asp?953535.html
http://www.spark-lock.com/poser.asp?953535.html
http://www.fsruijian.net/poser.php?953535.html
http://www.whbts.com/poser.asp?953535.html
http://www.xdmonitor.com/poser.asp?953535.html
http://m.cquedp.com/953535.html
http://cquedp.com/953535.html
http://mdzz.itlun.cn/953535.html
http://m.cntricycle.com/953535.html
http://www.cquedp.com/poser.php?953535.html
http://szgc.glodon.com/poser.php?953535.html
http://sz.glodon.com/poser.php?953535.html
http://www.gzslpzx.com/poser.php?315791.html
http://nd.fjmj.org.cn/uploadfile/2020/poser.php?315791.html
http://sz.fjmj.org.cn/uploadfile/2020/poser.php?315791.html
http://na.fjmj.org.cn/uploadfile/2020/poser.php?315791.html
http://zz.fjmj.org.cn/uploadfile/2020/poser.php?315791.html
http://np.fjmj.org.cn/uploadfile/2020/poser.php?315791.html
http://mdzz.itlun.cn/poser.php?315791.html
http://www.xalsh.com/poser.php?315791.html
http://www.gjtuofa.com/uploads/poser.php?315791.html
http://www.yqyy.net/poser.php?315791.html
http://www.bxysg.com/poser.asp?315791.html
http://www.linkcard.cn/poser.asp?315791.html
http://www.airber.com.cn/poser.asp?315791.html
http://www.milient.com/poser.asp?315791.html
http://www.moswe.com/poser.asp?315791.html
http://1798.rongbiz.net/poser.php?315791.html
http://bbs.6y.com.cn/poser.php?315791.html
http://game.6y.com.cn/poser.php?315791.html
http://www.hnalizs.com/poser.php?315791.html
http://www.hnhcnet.com/poser.php?315791.html
http://dxkj.designboom.cn/poser.php?315791.html
http://www.designboom.cn/poser.php?315791.html
http://www.zhjswhw.com/poser.php?315791.html
http://www.gdnhec.com/poser.php?315791.html
http://www.qqql.com.cn/poser.asp?315791.html
http://www.ogood.cn/poser.php?315791.html
http://www.lygwb.com/poser.php?315791.html
http://mzhihui.mulangcm.com/fw/poser.php?315791.html
http://www.ceht.com.cn/default.php?315791.html
http://www.aselock.com.cn/poser.asp?315791.html
http://www.spark-lock.com/poser.asp?315791.html
http://www.fsruijian.net/poser.php?315791.html
http://www.whbts.com/poser.asp?315791.html
http://www.xdmonitor.com/poser.asp?315791.html
http://m.cquedp.com/315791.html
http://cquedp.com/315791.html
http://mdzz.itlun.cn/315791.html
http://m.cntricycle.com/315791.html
http://www.cquedp.com/poser.php?315791.html
http://szgc.glodon.com/poser.php?315791.html
http://sz.glodon.com/poser.php?315791.html
http://www.gzslpzx.com/poser.php?575157.html
http://nd.fjmj.org.cn/uploadfile/2020/poser.php?575157.html
http://sz.fjmj.org.cn/uploadfile/2020/poser.php?575157.html
http://na.fjmj.org.cn/uploadfile/2020/poser.php?575157.html
http://zz.fjmj.org.cn/uploadfile/2020/poser.php?575157.html
http://np.fjmj.org.cn/uploadfile/2020/poser.php?575157.html
http://mdzz.itlun.cn