PYTHON(6)基于BASE64加密输出到txt
2020-01-30 本文已影响0人
弗兰克万岁
def mylock(name,txt):
import base64
root='C:'
'''
txt should add b''
'''
if txt!='null':
try:
os.mkdir(root + 'setting')
except Exception as e:
print(e)
try:
with open(os.path.join(root, 'setting/%s.dat' % name), 'wb') as f:
f.write(base64.b64encode(bytes(txt,'utf-8')))
return 1 # base64加密
except Exception as e:
print(e)
def unlock(name):
import base64
try:
if os.path.exists(root + '/setting') is False:
os.mkdir(root + '/setting')
with open(os.path.join(root, 'setting/%s.dat' % name), 'r') as f:
res = base64.b64decode(f.read())
return res
except Exception as e:
print(e)
return 0
def output():
#以utf8的方式输出
res=unlock(name)
print(str(res,'utf-8')