为什么我的第一个和最后一个盐返回同样的东西?

时间:2016-07-22 22:35:44

标签: python hash

我正在学习如何在Python中进行哈希,并且我已经遇到过这个部分,我的第一个和最后一个盐将返回相同的输出。

import hashlib


def obtain_password():
    password = raw_input('Enter a password: ')
    hash_password(password)


def hash_password(password):
    salt = 'first salt'
    second_salt = 'second salt'
    final_salt = 'final salt'

    first_alg = hashlib.md5()
    first_alg.update(password + salt)
    first_hash = first_alg.hexdigest()

    second_alg = hashlib.sha256()
    second_alg.update(first_hash + second_salt)
    second_hash = second_alg.hexdigest()

    final_alg = hashlib.md5()
    final_alg.update(second_hash + final_salt)
    final_hash = final_alg.hexdigest()

    print "Password: {}".format(password)
    print "First Salt: {}".format(salt)
    print "Second Salt: {}".format(second_salt)
    print "Final Salt: {}".format(final_salt)
    print "First Hash: {}".format(first_hash)
    print "Second Hash: {}".format(second_hash)
    print "Final Hash: {}".format(final_hash)
    return final_hash


if __name__ == '__main__':
    obtain_password()

正如您所看到的那样,我有三种不同的字符串,first saltsecond saltfinal salt。但是当运行时,我得到以下输出:

Enter a password: Testing!23
Password: Testing!23
First Salt: final salt
Second Salt: second salt
Final Salt: final salt
First Hash: 78db908227eceb53f3dccecaa52dd5c1
Second Hash: eda250daa7839eb0eda41630d9a08b27d97be344908999e63b0bd43069183a1d
Final Hash: f8d314290d48d6fbf1a21d2bf9b1e94f

我获得该输出的具体原因是什么??

0 个答案:

没有答案