Hex to Base64 conversion in Python

前端 未结 7 1209
一整个雨季
一整个雨季 2021-02-04 03:47

I want to convert a simple HEX string such as 10000000000002ae to Base 64.

The hex string is to be converted to bytes, and the bytes are then encoded to base64 notation,

7条回答
  •  南旧
    南旧 (楼主)
    2021-02-04 04:03

    Python 2 has native support for both HEX and base64 encoding:

    encoded = HEX_STRING.decode("hex").encode("base64")
    

    (if you are using Python 3, see Eana Hufwe or Ali's answers instead)

提交回复
热议问题