Wie man Base64 zu Hex mit Python dekodiert

Das folgende Beispiel dekodiert einen Base64-String und re-kodiert ihn zu Hex. Es benötigt nur eingebaute Bibliotheken

Dies ist besonders nützlich beim Arbeiten mit Binärdaten, die als Base64 kodiert sind.

base64_to_hex.py
import base64

def base64_to_hex(base64_string):
    # Decode the base64 string
    decoded_bytes = base64.b64decode(base64_string)
    # Convert the decoded bytes to a hex string
    hex_string = decoded_bytes.hex()
    return hex_string

# Example usage
example_base64 = "SGVsbG8gd29ybGQ="
base64_to_hex(example_base64)

Check out similar posts by category: Python