Skip to Content
oxcrypto

SHA-2

SHA-2 digest algorithms.

Example

from oxcrypto.hash.sha2 import SHA2

algorithm = SHA2.SHA256
digest = algorithm.digest(b"hello")
assert digest == algorithm.digest_chunks([b"he", b"llo"])

hasher = algorithm.new()
hasher.update(b"he")
hasher.update(b"llo")
assert hasher.digest() == digest
print(digest.hex())

Variants

  • SHA2.SHA224
  • SHA2.SHA256
  • SHA2.SHA384
  • SHA2.SHA512
  • SHA2.SHA512_224
  • SHA2.SHA512_256

Methods

digest(self, data: bytes, /) -> bytes
digest_chunks(self, chunks: Iterable[bytes], /) -> bytes
new(self) -> Hasher

On this page