DevToolsForYou

Hash Generator in Ruby — Code Examples

Hash Generator in RubyUse 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.

Ruby's Digest module (standard library) covers MD5, SHA-1, SHA-256, and SHA-512. For HMAC, use the OpenSSL module.

Ruby
require 'digest'
require 'openssl'

input = "Hello, world!"

# SHA-256
sha256 = Digest::SHA256.hexdigest(input)
puts sha256
# 315f5bdb76d078c43b8ac0064e4a0164612b1fce77c869345bfc94c75894edd3

# SHA-512
sha512 = Digest::SHA512.hexdigest(input)
puts sha512

# MD5 (not for security use)
md5 = Digest::MD5.hexdigest(input)
puts md5 # 6cd3556deb0da54bca060b4c39479839

# SHA-256 as raw bytes then re-encode as Base64
raw = Digest::SHA256.digest(input)
puts raw.unpack1('H*') # same hex as hexdigest

# HMAC-SHA256
hmac = OpenSSL::HMAC.hexdigest("SHA256", "secret-key", input)
puts hmac
Notes & gotchas
  • Digest::SHA256.hexdigest is a one-shot convenience method; use Digest::SHA256.new for streaming large inputs.
  • Never use MD5 or SHA-1 for passwords — use BCrypt (bcrypt gem) or Argon2 (argon2 gem) instead.
  • OpenSSL::HMAC is part of Ruby's standard library since Ruby 2.0; no gem required.
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