DevToolsForYou

Hash Generator in PHP — Code Examples

Hash Generator in PHPUse the online tool →

Cryptographic hash functions convert input data into a fixed-size digest. SHA-256 is the current standard for security-sensitive use cases; MD5 is broken for security but still used for checksums.

PHP's hash() function supports over 50 algorithms. Use hash_hmac() for HMAC authentication.

PHP
<?php

$input = "Hello, world!";

// SHA-256
$sha256 = hash("sha256", $input);
echo $sha256 . "
";
// 315f5bdb76d078c43b8ac0064e4a0164612b1fce77c869345bfc94c75894edd3

// SHA-512
$sha512 = hash("sha512", $input);
echo $sha512 . "
";

// MD5 (checksums only — not for security)
$md5 = md5($input); // or hash("md5", $input)
echo $md5 . "
"; // 6cd3556deb0da54bca060b4c39479839

// Raw binary output (pass true as third arg)
$raw = hash("sha256", $input, true);
echo base64_encode($raw) . "
";

// HMAC-SHA256
$hmac = hash_hmac("sha256", $input, "secret-key");
echo $hmac . "
";

// List all available algorithms
// print_r(hash_algos());
Notes & gotchas
  • Never use MD5 or SHA-1 for password hashing — use password_hash() with PASSWORD_BCRYPT or PASSWORD_ARGON2ID.
  • hash_equals() performs a timing-safe comparison to prevent timing attacks.
  • Pass true as the third argument to hash() to get raw binary output instead of hex.
Try it in your browser

Need to hash md5/sha without writing code? The Hash Generator runs entirely in your browser — paste your input and get the result instantly. No signup, no install, no data sent to a server.

Open Hash MD5/SHA
Hash Generator in other languages