Home » Generate SHA-512 Hashes using Python

Generate SHA-512 Hashes using Python

Java SE 11 Programmer II [1Z0-816] Practice Tests
Spring Framework Basics Video Course
1 Year Subscription
Java SE 11 Programmer I [1Z0-815] Practice Tests
Java SE 11 Developer (Upgrade) [1Z0-817]
Oracle Java Certification

PyCryptodome is a self-contained Python package of low-level cryptographic primitives.

PyCryptodome is a fork of PyCrypto. It brings the following enhancements with respect to the last official version of PyCrypto (2.6.1):

  • Authenticated encryption modes (GCM, CCM, EAX, SIV, OCB)
  • Accelerated AES on Intel platforms via AES-NI
  • First class support for PyPy
  • Elliptic curves cryptography (NIST P-curves; Ed25519, Ed448)
  • Better and more compact API (nonce and iv attributes for ciphers, automatic generation of random nonces and IVs, simplified CTR cipher mode, and more)
  • SHA-3 hash algorithms (FIPS 202) and derived functions (NIST SP-800 185):
    • SHAKE128 and SHA256 XOFs
    • cSHAKE128 and cSHAKE256 XOFs
    • KMAC128 and KMAC256
    • TupleHash128 and TupleHash256
  • KangarooTwelve XOF (derived from Keccak)
  • Truncated hash algorithms SHA-512/224 and SHA-512/256 (FIPS 180-4)
  • BLAKE2b and BLAKE2s hash algorithms
  • Salsa20 and ChaCha20/XChaCha20 stream ciphers
  • Poly1305 MAC
  • ChaCha20-Poly1305 and XChaCha20-Poly1305 authenticated ciphers
  • scrypt, bcrypt, HKDF, and NIST SP 800 108r1 Counter Mode key derivation functions
  • Deterministic (EC)DSA and EdDSA
  • Password-protected PKCS#8 key containers
  • Shamir’s Secret Sharing scheme
  • Random numbers get sourced directly from the OS (and not from a CSPRNG in userspace)
  • Simplified install process, including better support for Windows
  • Cleaner RSA and DSA key generation (largely based on FIPS 186-4)
  • Major clean ups and simplification of the code base

Install PyCryptodome library from the command line:

pip install pycryptodome

Generate SHA-512/256 hash:

 

from Crypto.Hash import SHA512

text = 'Hello from maxpython'
hashObject = SHA512.new(truncate='256')
hashObject.update(text.encode('utf-8'))
digest = hashObject.hexdigest()

print(digest)

I saw this in the repl window

>> %Run code.py
f3f72adc4464abc57f414018d0627a299a44561d5372686fe306884affede581

Generate SHA-512/224 hash:

 

from Crypto.Hash import SHA512

text = 'Hello from maxpython'
hashObject = SHA512.new(truncate='224')
hashObject.update(text.encode('utf-8'))
digest = hashObject.hexdigest()

print(digest)

I saw this in the repl window

>> %Run code.py
f83f0c4b39c41f399f4531e8ff37a18d329b3f1e0e32f7d4bae267bb

 

You may also like

Leave a Comment

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More