Python单向哈希加密计算
#Python forensics
#Simple program to generate the SHA-256
#one-way cryptographic hash of a given string
#Step 1
#Instruct the interpreter to import the Standard library module hashlib
import hashlib
#print a message to the user
print
print("Simple program to generate the SHA-256 Hash of the String 'Pyhton forensics'")
print
#define a string with the desired text
myString = 'Pythonforensics'
#create an object named hash which is of type sha256
Hash = hashlib.sha256()
#utilize the up data method of the hash object to generate the SHA256 hash of myString
#SHA256 hash of myString
Hash.update(myString.encode('utf8'))
#obtain the generated hex values of the SHA256 Hash from the object by utilizing the hexdigest method
hexSHA256 = Hash.hexdigest()
#print out the result and utilize the upper method to convert all the hex characters to uppercase
print("SHA-256Hash:" + hexSHA256.upper())
print
print('Processingcompleted')
输出结果:
Simple program to generate the SHA-256 Hash of the String ‘Pyhton forensics’
SHA-256Hash:00CF3CD9AB91D70EC48133F91690DB1E6C24AD4F82FBABDB22B189B2A45351F5
Processingcompleted