Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

concatenation of two or more base64 strings in python

I'm tring to concatenate two strings encoded to base64 but it doesn't really work, just prints the first string in concatanation:

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"
like image 638
Eduardo Dalapicola Avatar asked May 17 '16 14:05

Eduardo Dalapicola


1 Answers

You are decoding a string that is concatenation of two base64 strings. This is not correct. You should do something like this -

base64.b64decode(base64.b64encode("StringA" + "StringB"))
like image 189
Mitesh Budhabhatti Avatar answered Sep 25 '22 22:09

Mitesh Budhabhatti