How to generate SHA-256 hashes?

0127

You can generate SHA-256 hashes in various programming languages. Here are examples in Python and Bash:

Python

You can use the hashlib library:

import hashlib

# Input data
data = "Hello, World!"
# Generate SHA-256 hash
sha256_hash = hashlib.sha256(data.encode()).hexdigest()
print(sha256_hash)

Bash

You can use the sha256sum command:

echo -n "Hello, World!" | sha256sum

Node.js

You can use the crypto module:

const crypto = require('crypto');

const data = "Hello, World!";
const sha256Hash = crypto.createHash('sha256').update(data).digest('hex');
console.log(sha256Hash);

Feel free to ask if you need examples in another language or further assistance!

0 Comments

no data
Be the first to share your comment!