从数据库检索时为什么编码数据会发生变化

时间:2015-03-10 04:35:41

标签: python mysql encryption

我遇到数据损坏问题。我在输入数据库后保存数据。但是,在重新比较后比较相同的数据时,我发现价值不相等。

对我来说,保存数据后数据会发生变化。

    RPasswd = "pw2013"
    Passwd = "2password"
    TVkey = hashlib.sha256(Passwd).digest()
    #encode password for before encryption to remove special characters
    Rencoded = base64.b64encode(RPasswd)
    #pad the length to a multiple of 16 with a space character for encryption
    Rencoded += ((16 - len(Rencoded)%16) * " ")
    #encrypt password to be stored as the user's credentials
    encRPasswd = AES.new(TVkey, AES.MODE_ECB).encrypt(Rencoded)

    # Open database connection
    db = MySQLdb.connect("localhost","root","root","db" )

    # prepare a cursor object using cursor() method
    cursor = db.cursor()

    try:
        cursor.execute("select `group_id`, `group`, `password` from db.groups where group_id = 1 ")
        #print "number of rows" + cursor.rowcount
        results = cursor.fetchall()

        for row in results:
            print row[0] 
            print row[1]
            pw = row[2]   

        print "test"
        db.commit()
    except:

        db.rollback()


    # disconnect from server
    db.close()
    if encRPasswd == pw:
        print "samme"
    else:
        print "not same"

当我运行代码时,我得到的不一样。理想情况下,两个值应该相同。

任何提示?

0 个答案:

没有答案