
Hashing is a fundamental part of modern computing. It ensures data integrity, verifies passwords, and secures communications.
Whether you're validating downloads, protecting user credentials, or checking file integrity, hash functions like MD5, SHA1, SHA256, and others are your go-to tools.
In this post, you'll learn how to generate hashes in Python and other popular programming languages, including JavaScript, C#, Java, and C++ using the following algorithms:
And if you just want to hash something right now, you can instantly do it with DevGizmo's Hash Generator.
A hash function converts any input (text, file, password) into a fixed-length string of characters - a hash value or digest
For example:
Input: "DevGizmo"
SHA256 Hash: 1f97b9b5e3e4d3e5a73c5c6e703f12c47e869b8d87236b2f9eaa7d97e9d8c4b1
Hashes are:
Python's built-in hashlib library supports all major algorithms.
import hashlib
text = "DevGizmo".encode('utf-8')
print("MD5:", hashlib.md5(text).hexdigest())
print("SHA1:", hashlib.sha1(text).hexdigest())
print("SHA224:", hashlib.sha224(text).hexdigest())
print("SHA256:", hashlib.sha256(text).hexdigest())
print("SHA384:", hashlib.sha384(text).hexdigest())
print("SHA512:", hashlib.sha512(text).hexdigest())
Output Example:
MD5: 7b3fa84d8bde731e5b85ef7f6f9428c7
SHA1: 715aef9852d3e6ec5ab57e14dcddc0c0b09db49b
SHA256: 1f97b9b5e3e4d3e5a73c5c6e703f12c47e869b8d87236b2f9eaa7d97e9d8c4b1
...
Tip:
Use hashlib.algorithms_available to see all supported algorithms on your system.
Node.js has hashing support through the built-in crypto module
const crypto = require('crypto');
const text = 'DevGizmo';
function hash(algorithm) {
return crypto.createHash(algorithm).update(text).digest('hex');
}
console.log("MD5:", hash('md5'));
console.log("SHA1:", hash('sha1'));
console.log("SHA224:", hash('sha224'));
console.log("SHA256:", hash('sha256'));
console.log("SHA384:", hash('sha384'));
console.log("SHA512:", hash('sha512'));
Output Example:
MD5: 7b3fa84d8bde731e5b85ef7f6f9428c7
SHA1: 715aef9852d3e6ec5ab57e14dcddc0c0b09db49b
SHA256: 1f97b9b5e3e4d3e5a73c5c6e703f12c47e869b8d87236b2f9eaa7d97e9d8c4b1
...C# provides hashing utilities under System.Security.Cryptography.
using System;
using System.Security.Cryptography;
using System.Text;
class Program
{
static void Main()
{
string text = "DevGizmo";
byte[] bytes = Encoding.UTF8.GetBytes(text);
Console.WriteLine("MD5: " + BitConverter.ToString(MD5.Create().ComputeHash(bytes)).Replace("-", "").ToLower());
Console.WriteLine("SHA1: " + BitConverter.ToString(SHA1.Create().ComputeHash(bytes)).Replace("-", "").ToLower());
Console.WriteLine("SHA256: " + BitConverter.ToString(SHA256.Create().ComputeHash(bytes)).Replace("-", "").ToLower());
Console.WriteLine("SHA384: " + BitConverter.ToString(SHA384.Create().ComputeHash(bytes)).Replace("-", "").ToLower());
Console.WriteLine("SHA512: " + BitConverter.ToString(SHA512.Create().ComputeHash(bytes)).Replace("-", "").ToLower());
}
}
Output Example:
MD5: 7b3fa84d8bde731e5b85ef7f6f9428c7
SHA1: 715aef9852d3e6ec5ab57e14dcddc0c0b09db49b
SHA256: 1f97b9b5e3e4d3e5a73c5c6e703f12c47e869b8d87236b2f9eaa7d97e9d8c4b1
...In Java, hashing is done via MessageDigest.
import java.security.MessageDigest;
public class HashExample {
public static void main(String[] args) throws Exception {
String text = "DevGizmo";
String[] algorithms = {"MD5", "SHA-1", "SHA-224", "SHA-256", "SHA-384", "SHA-512"};
for (String algo : algorithms) {
MessageDigest md = MessageDigest.getInstance(algo);
byte[] digest = md.digest(text.getBytes());
System.out.println(algo + ": " + bytesToHex(digest));
}
}
private static String bytesToHex(byte[] bytes) {
StringBuilder sb = new StringBuilder();
for (byte b : bytes) sb.append(String.format("%02x", b));
return sb.toString();
}
}
Output Example:
MD5: 7b3fa84d8bde731e5b85ef7f6f9428c7
SHA1: 715aef9852d3e6ec5ab57e14dcddc0c0b09db49b
SHA256: 1f97b9b5e3e4d3e5a73c5c6e703f12c47e869b8d87236b2f9eaa7d97e9d8c4b1
...
Note: SHA-224 may require a newer JDK (Java 11+)
With OpenSSL, you can easily hash strings from the following code.
#include <openssl/evp.h>
#include <iostream>
#include <iomanip>
#include <string>
void hash(const std::string& input, const EVP_MD* algo) {
unsigned char hash[EVP_MAX_MD_SIZE];
unsigned int length;
EVP_MD_CTX* ctx = EVP_MD_CTX_new();
EVP_DigestInit_ex(ctx, algo, NULL);
EVP_DigestUpdate(ctx, input.c_str(), input.size());
EVP_DigestFinal_ex(ctx, hash, &length);
EVP_MD_CTX_free(ctx);
for (unsigned int i = 0; i < length; i++)
std::cout << std::hex << std::setw(2) << std::setfill('0') << (int)hash[i];
std::cout << std::endl;
}
int main() {
std::string input = "DevGizmo";
std::cout << "SHA256: ";
hash(input, EVP_sha256());
}
| Algorithm | Speed | Security | Recommended Use |
|---------------|---------------|-----------------------|--------------------------------|
| MD5 | Very fast | Weak | Checksums, file integrity only |
| SHA1 | Fast | Broken | Legacy systems only |
| SHA224 | Moderate | Secure | Compact hashes |
| SHA256 | Good | Secure | General-purpose hashing |
| SHA384 | Slower | Very secure | Digial signatures |
| SHA512 | Slower | Extremely secure | Sensitive data hashing |Need a quick hash?
Use DevGizmo's Hash Generator to compute MD5, SHA, SHA1, SHA224, SHA256, and more directly in your browser.
It's free, secure, and runs entirely client-side.
Hashes are one of the simplest yet most powerful tools in programming.
Whether you're verifying data, storing credentials, or checking integrity, hash algorithms like SHA256 and SHA512 give you both speed and security.
With just a few lines of code in Python, JavaScript, C#, Java, or C++ - you can generate cryptographic hashes that fit your needs.
Need one instantly? Visit DevGizmo's Hash Generator and try it online.
Learn how to generate MD5, SHA1, SHA224, SHA256, SHA384, and SHA512 hashes in Python, JavaScript, C#, Java, and C++. This step-by-step guide explains hashing basics, shows code for each algorithm, and highlights which hash types are best for security and performance.