用Python将HEX字符串转换为base64



是否可以转换输入?

从base64导入b64encode,b64decode

d=输入('你的十六进制字符串是什么?'(

b64=b64encode(字节.fromhex(d((.decode((

打印("您的十六进制base64是:",b64(

**b64 = b64encode(bytes.fromhex(d)).decode()

ValueError:在fromhex((arg的位置1**处发现非十六进制数字

花了几个小时后,我终于想明白了。不得不更改b64变量并取出.decode((

d = input("Enter HEX here: ")
b64 = b64encode(bytes.fromhex(d))
print("Your HEX in base64 is:", b64)

编码可以在codecs模块中找到
尝试使用此

import codecs
b64 = codecs.encode(codecs.decode(d, 'hex'), 'base64').decode()

最新更新