I am trying to recreate a java program in python, but I am stuck at this point
import android.util.Base64 -> this is the package
Base64.encodeToString(bytes, 11)
The python module for encoding with base64 only gets one parameter, which is bytes
.
apparently, according to the android docs, the second parameter is supposed to indicate a flag
, but I can't find any information about the number 11
What does this mean and how can I implement this in python?
CodePudding user response:
11 is a combination of flags (or-ed together), specifically:
- NO_PADDING, which has value
1
- NO_WRAP which has value
2
and - URL_SAFE which has value
8
.
I don't know the exact way to reproduce this in Python, but I believe base64.urlsafe_b64encode
gets you halfway there by implementing the equivalent of URL_SAFE
. For NO_PADDING
you could simply trim any trailing padding (i.e. =
charcters) in the output.