一个简单的api,用于加密python dict并将其保存到文件中。
pydictfileenc的Python项目详细描述
pydictfileency
一个简单的api,用于使用aes256将python dict加密到文件中。交互直接在文件和内存之间(不会创建解密的file.tmp)。加密的数据以字符串形式保存在光盘上的文件中。如果一个人在开发一个单线程应用程序,它可以被用作加密的“sql”。 这个api是stackoverflow上答案的集合。
安装
pip install pydictfileency
用法
python dict(一组)被收集在将直接操作的“容器”中。
示例和API
from pydictfileency import PyDictFileEncy
创建容器
#-----------------------------------------------------
# create a new filedict (with password = 'password')
container = PyDictFileEncy('encrypted.dat','password')
container.connect()
# a file is created. One can check the context in it.
连接到它(验证密码)
#-----------------------------------------------------
# connect to a filedict
container = PyDictFileEncy('encrypted.dat','password')
container.connect()
print(container.IsConnected())
# a filedict is connect. One can try another password.
创建表(表是python dict)
#-----------------------------------------------------
# create a table
container = PyDictFileEncy('encrypted.dat','password')
container.connect()
container.CreateTableIfNotExist('testTable')
# remenber to save it
container.Save()
显示所有表格
#-----------------------------------------------------
# get all the tables in container
container = PyDictFileEncy('encrypted.dat','password')
container.connect()
# return a python dict 'dict_keys' type
l = container.GetTableList()
print(l)
在容器中获取python dict。你可以做手术。
#-----------------------------------------------------
# get a normal python dict in the container so one can interact with it
container = PyDictFileEncy('encrypted.dat','password')
container.connect()
d = container.GetTable('testTable')
print(type(d),d)
# --- inser an element
d['new'] = 'hellow'
# remenber to save it
container.Save()
删除表格
#-----------------------------------------------------
# remove a table
container = PyDictFileEncy('encrypted.dat','password')
container.connect()
container.DropTable('testTable')
# remenber to save it
container.Save()
重置新密码
#-----------------------------------------------------
# reset password
container = PyDictFileEncy('encrypted.dat','password')
container.connect()
container.SetPassword('newpassword')
# remenber to save it
container.Save()
# the container itself is already renewed
print( container.IsConnected() )