Python中的Hex转换为Base64 [英] Hex to Base64 conversion in Python

查看:2035
本文介绍了Python中的Hex转换为Base64的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将一个简单的十六进制字符串(例如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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆