Monkey Raptor

Sunday, November 15, 2015

Python: \n (New Line) from base64 Conversion

We can use different keywords to implement the string encoding from base64 module.

Start by importing the module like so:

import base64

# then, either:

  1. "the string to be converted".encode("base64")
    or add the "strict" option
    "the string to be converted".encode("base64", "strict")
    or
    base64.encode("the string to be converted")
  2. base64.encodestring("the string to be converted")
  3. base64.b64encode("the string to be converted")
  4. base64.standard_b64encode("the string to be converted")
  5. base64.urlsafe_b64encode("the url string to be converted")

The first two methods will yield \n as the tail of the output.

Those could be "dangerous" for authentication. Because if we forgot to include the front-end converter (such as in JavaScript, like adding replace or other), or other string filter(s) within the Python itself, the stuff would fail.

And if the certain API we're experimenting with is implementing usage filters (which is for certain), we could be blacklisted, because of the constant failures. And then, with many lucks, our connection/machine might be detected as a legit spammer. YAY!
Well, that would rarely happen.


In Conclusion

It's recommended to use the others besides the first two. The:

  1. base64.b64encode("the string to be converted")
  2. base64.standard_b64encode("the string to be converted")
  3. base64.urlsafe_b64encode("the url string to be converted")

Official documentation

Python's base64 library documentation
Python: \n (New Line) from base64 Conversion
https://monkeyraptor.johanpaul.net/2015/11/python-n-new-line-from-base64-conversion.html

No comments

Post a Comment

Tell me what you think...