Python中的Hex转换为Base64 [英] Hex to Base64 conversion in Python
问题描述
我想将一个简单的十六进制字符串(例如10000000000002ae)转换为Base 64.
将十六进制字符串转换为字节,然后将字节编码为base64表示法,因此该字符串的预期输出为:EAAAAAAAAq4 =
我在网上找到了一个工具。 http://tomeko.net/online_tools/hex_to_base64.php?lang=en
但是我有一堆HEX值需要在脚本中进行转换。
Python对HEX和base64编码都有本地支持:
$ b
encoded = HEX_STRING.decode(hex ).encode(base64)
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, so the expected output for that string: EAAAAAAAAq4=
I found a tool online. http://tomeko.net/online_tools/hex_to_base64.php?lang=en
But I have a bunch of HEX values that I need to convert in a script.
Python has native support for both HEX and base64 encoding:
encoded = HEX_STRING.decode("hex").encode("base64")
这篇关于Python中的Hex转换为Base64的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!