How to decode Base64 to Hex using Python

The following example will decode a Base64 string and re-encode it to hex. It requires only built-in libraries

This is particularly useful when working with binary data encoded as Base64.

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)