#!/bin/bash # |-------------------------------------------------------------------------- # | APP_SECRET generator (c) 2019 Laravel Holdings LLC # | # | MIT License # | # | Permission is hereby granted, free of charge, to any person obtaining a copy # | of this software and associated documentation files (the "Software"), to deal # | in the Software without restriction, including without limitation the rights # | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # | copies of the Software, and to permit persons to whom the Software is # | furnished to do so. # |-------------------------------------------------------------------------- # | Script to generate a secure 32-byte (256-bit) application secret in hexadecimal format. # --- Configuration --- # Number of raw bytes to generate (32 bytes = 256 bits) BYTES_LENGTH=32 # --- Checks --- # Check if xxd command is available. If not, exit silently with error code. if ! command -v xxd &> /dev/null; then exit 1 # Exit without output fi # Check if /dev/urandom is accessible. If not, exit silently with error code. if [ ! -r /dev/urandom ]; then exit 1 # Exit without output fi # --- Secret Generation and Output --- # Generate random bytes from /dev/urandom, convert to hex, and remove the trailing newline. # The result is printed directly to stdout. head -c "${BYTES_LENGTH}" /dev/urandom | xxd -p | tr -d '\n' exit 0