SHA in Python

 

Code Example


SHA, ( Secure Hash Algorithms ) are set of cryptographic hash functions defined by the language to be used for various applications such as password security etc. Some variants of it are supported by Python in the “hashlib” library. These can be found using “algorithms_guaranteed” function of hashlib.


# test.py

import hashlib


def Encode_SHA256(data='kuntal'):

    result = hashlib.sha256(data.encode())

    return result.hexdigest()


def Encode_SHA384(data='kuntal'):

    result = hashlib.sha384(data.encode())

    return result.hexdigest()


def Encode_SHA224(data='kuntal'):

    result = hashlib.sha224(data.encode())

    return result.hexdigest()


def Encode_SHA512(data='kuntal'):

    result = hashlib.sha512(data.encode())

    return result.hexdigest()


print("SHA256")

print(Encode_SHA256(), "len is : ", len(Encode_SHA256()))

print("\nSHA384")

print(Encode_SHA384(), "len is : ", len(Encode_SHA384()))

print("\nSHA224")

print(Encode_SHA224(), "len is : ", len(Encode_SHA224()))

print("\nSHA512")

print(Encode_SHA512(), "len is : ", len(Encode_SHA512()))


Screenshot :





Quiz Level 1

Quiz Level 2


Request Me


Comments

  1. Sir hashlib is builtin or with pip I need to install?

    ReplyDelete

Post a Comment

Popular posts from this blog

How To Create .ENV File in Python

Create a Large file for Test Data Processing using Python

How to solve the Liner Equation using Python