Files
go-nkode/secure_bytes.sh
2024-10-03 15:37:23 -05:00

15 lines
510 B
Bash

#!/bin/bash
# Define the number of bytes you want to generate
num_bytes=16
# Use dd to read cryptographically secure bytes from /dev/urandom
# and convert them to hexadecimal using od
secure_bytes=$(dd if=/dev/urandom bs=1 count=$num_bytes 2>/dev/null | od -An -tx1)
# Remove leading/trailing spaces and concatenate the hex bytes into a single string
secure_bytes=$(echo $secure_bytes | tr -d ' \n')
# Output the result as a hexadecimal string
echo "Cryptographically secure bytes (as hex): $secure_bytes"