Returns: int: Decimal representation """ # Remove common separators and prefixes cleaned = hex_string.replace(':', '').replace(' ', '').lower() if cleaned.startswith('0x'): cleaned = cleaned[2:]
import os, subprocess
When using programming languages, you may need to prefix your string with 0x or specify the base (16) explicitly. convert certificate serial number hex to decimal
If you have hundreds of certificates, automate the task.
openssl x509 -in certificate.pem -noout -serial | cut -d= -f2 | tr -d '\n' | while read hex; do echo "ibase=16; $hex" | bc; done Returns: int: Decimal representation """ # Remove common
echo "ibase=16; 0E6B3A7F1D2C" | bc
for cert in *.crt; do hex_serial=$(openssl x509 -in "$cert" -noout -serial | cut -d= -f2) decimal_serial=$(echo "ibase=16; $hex_serial" | bc) echo "$cert: $decimal_serial" done It is fast, accurate, and works on Linux,
OpenSSL recognizes the 0x prefix as hexadecimal. It is fast, accurate, and works on Linux, macOS, and Windows (via WSL or Git Bash).
Look for the Serial Number: field. If it is short, it displays as decimal; if it is long, it displays as hex, but you can pipe it to bc (see Method B). 3. Method B: Using the Command Line (Linux/macOS)