Skip to content

Commit

Permalink
[ADD] sha256 method for convenience
Browse files Browse the repository at this point in the history
  • Loading branch information
mccwdev committed Nov 13, 2023
1 parent e37fa6f commit 0749ed4
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions bitcoinlib/encoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -884,6 +884,23 @@ def double_sha256(string, as_hex=False):
return hashlib.sha256(hashlib.sha256(string).digest()).hexdigest()


def sha256(string, as_hex=False):
"""
Get SHA256 hash of string
:param string: String to be hashed
:type string: bytes
:param as_hex: Return value as hexadecimal string. Default is False
:type as_hex: bool
:return bytes, str:
"""
if not as_hex:
return hashlib.sha256(string).digest()
else:
return hashlib.sha256(string).hexdigest()


def ripemd160(string):
try:
return RIPEMD160.new(string).digest()
Expand Down

0 comments on commit 0749ed4

Please sign in to comment.