【问题标题】:concatenation of two or more base64 strings in pythonpython中两个或多个base64字符串的连接
【发布时间】:2016-05-17 14:08:33
【问题描述】:

我正在尝试连接两个编码为 base64 的字符串,但它并没有真正起作用,只是在连接中打印第一个字符串:

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"

【问题讨论】:

  • 你为什么要这样做?
  • 因为我需要在代码的不同时刻连接字符串
  • 好吧...你为什么需要这样做?

标签: python base64 concatenation encode


【解决方案1】:

您正在解码一个由两个 base64 字符串连接而成的字符串。这是不正确的。你应该做这样的事情 -

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-06-11
    • 2018-03-10
    • 1970-01-01
    • 2013-11-05
    • 2017-07-22
    • 1970-01-01
    • 2019-10-23
    相关资源
    最近更新 更多