python中两个或多个base64字符串的串联

2024-04-19 17:54:30 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试连接两个编码为base64的字符串,但它实际上不起作用,只打印concatation中的第一个字符串:

q = base64.b64encode("StringA")
print q # prints an encoded string
q = q+base64.b64encode("StringB")
print q # prints an encoded string

print base64.b64decode(q) # just prints "StringA"

Tags: 字符串an编码stringprintsjustprintencoded
2条回答

您正在解码由两个base64字符串串联而成的字符串。这是不对的。你应该这样做-

base64.b64decode(base64.b64encode("StringA" + "StringB"))

这是有效的:

>>> ''.join([base64.b64encode("StringA"), base64.b64encode("StringB")])
'U3RyaW5nQQ==U3RyaW5nQg=='

相关问题 更多 >