Пример #1
0
def backupDbSingle(dbName, targetDir, password, user):
    if user is None:
        dbSysInst = dbSys.dbSysSmart()
    else:
        dbSysInst = dbSys.dbSysSmart(sessionBase.sessionInstanceBase(user))
        

    db = dbSysInst.getDb(dbName)
    res = []
    e = enc.encryptor()
    if not os.path.exists(targetDir):
        misc.ensureDir(targetDir)
    for i in db.keys():
        #print i
        #values = db.testFunc(i)
        values = db[i]
        encryptedValues = []
        for i in values:
            print i.encode('gbk', 'replace')
            encryptedValues.append(e.en(i, password))
        j = {"key":e.en(i, password), "value":encryptedValues,
            "encHash":unicode(md5.new(password).hexdigest())}

        res.append(j)
        
    #print res
    s = json.dumps(res, sort_keys=True, indent=4)
    f = open(os.path.join(targetDir, dbName+'_for_user_'+str(user)+'.json'),'w')
    f.write(s)
    f.close()
Пример #2
0
def dictListDecryptor(dictList, password):
    e = enc.encryptor()
    res = []
    for i in dictList:
        values = i["value"]
        decryptedValues = []
        for j in values:
            v = e.de(j, password)
            d = decryptedValues.append(v)
            #print v.encode('gbk', 'replace')
        j = {"db": i["db"], "user": i["user"], "key":e.de(i["key"], password), "value":decryptedValues}
        res.append(j)
    return res
Пример #3
0
def dictListEncryptor(dictList, password):
    e = enc.encryptor()
    res = []
    for i in dictList:
        values = i["value"]
        encryptedValues = []
        for j in values:
            print j.encode('gbk', 'replace')
            encryptedValues.append(e.en(j, password))
        j = {"db": i["db"], "user": i["user"], "key":e.en(i["key"], password), "value":encryptedValues,
            "encHash":unicode(md5.new(password).hexdigest())}
        res.append(j)
    return res