What is SHA-256 and why should we use it?
SHA-256 is a cryptographic hash function that produces a 256-bit hash value from a data input. It is part of the SHA-2 family of hash functions (for more details, please check out https://justcryptography.com/sha-2/) that were designed by the National Security Agency (NSA) and published by the National Institute of Standards and Technology (NIST) in 2001.
SHA-256 is a widely used hash function for a variety of applications, including the following:
- Password storage: SHA-256 is used to store passwords securely. When a user creates an account on a website or application, their password is converted into an SHA-256 hash and stored in the database. When the user logs in, their password is converted into an SHA-256 hash and compared to the hash stored in the database. If the two hashes match, then the user is successfully logged in.
- Digital signatures: SHA-256 can be used to create digital signatures. A digital signature is a cryptographic technique that allows the sender of a message to verify their identity and the integrity of the message. To create a digital signature, the sender calculates the SHA-256 hash of the message and then encrypts the hash with their private key. The sender then sends the message and the encrypted hash to the recipient. The recipient calculates the SHA-256 hash of the message and then decrypts the encrypted hash with the sender’s public key. If the two hashes match, then the recipient can be sure that the message is authentic and has not been tampered with.
- File integrity verification: SHA-256 can be used to verify the integrity of files. To do this, the SHA-256 hash of the file is calculated and then stored. When the file is needed, the SHA-256 hash of the file is calculated again and compared to the stored hash. If the two hashes match, then the file is known to be intact.
SHA-256 is considered to be a very secure hash function. It is resistant to collision attacks, meaning that it is very difficult to find two different inputs that produce the same hash value. It is also resistant to preimage attacks, meaning that it is very difficult to find the input that produces a given hash value.
Here are some reasons why you should use SHA-256:
- It is a very secure hash function
- It is widely used and supported
- It is relatively easy to implement
- It is free to use
If you need a secure way to store passwords, create digital signatures, or verify the integrity of files, then SHA-256 is a good choice.
Now that we have all the information we need, let’s start coding. As usual, we have to follow some typical steps to set up a new virtual environment:
- Create a new directory named Login_Skeleton.
- Enter this directory and write pipenv shell to create a new virtual environment.
- Install the streamlit and pillow packages.
- Create a new empty Python file named app.py.
- Launch your IDE (Sublime Text).