You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ORPA-pyOpenRPA/Resources/WPy64-3720/python-3.7.2.amd64/Lib/site-packages/Crypto/library/hash.py

24 lines
847 B

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import hashlib
from Naked.toolshed.file import FileReader
# ------------------------------------------------------------------------------
# PUBLIC
# ------------------------------------------------------------------------------
def generate_hash(filepath):
"""Public function that reads a local file and generates a SHA256 hash digest for it"""
fr = FileReader(filepath)
data = fr.read_bin()
return _calculate_sha256(data)
# ------------------------------------------------------------------------------
# PRIVATE
# ------------------------------------------------------------------------------
def _calculate_sha256(binary_string):
"""Private function that calculates a SHA256 hash digest for a binary string argument"""
return hashlib.sha256(binary_string).hexdigest()