EncrypC_5.py 659 B

12345678910111213141516171819202122232425262728293031
  1. def hash_key_salt(self):
  2. # --- convert key to hash
  3. # create a new hash object
  4. hasher = hashlib.new(self.hash_type)
  5. hasher.update(self.user_key)
  6. # turn the output key hash into 32 bytes (256 bits)
  7. self.hashed_key_salt["key"] = bytes(hasher.hexdigest()[:32], "utf-8")
  8. # clean up hash object
  9. del hasher
  10. # --- convert salt to hash
  11. # create a new hash object
  12. hasher = hashlib.new(self.hash_type)
  13. hasher.update(self.user_salt)
  14. # turn the output salt hash into 16 bytes (128 bits)
  15. self.hashed_key_salt["salt"] = bytes(hasher.hexdigest()[:16], "utf-8")
  16. # clean up hash object
  17. del hasher