Android Base64 URI codec bad base-64 exception handling

Source: Internet
Author: User

This essay introduces a commonly used BASE64 exception condition that is not easily found when encoding and decoding URIs.

Android uses NANOHTTPD as an HTTP server to provide HTTP data stream transmission to the application, using BASE64 to encode a resource, as follows (debug):

Resources:/storage/emulated/0/movies/the Mountain.mp4

Base64 after encoding: l3n0b3jhz2uvzw11bgf0zwqvmc9nb3zpzxmvvghlie1vdw50ywlulm1wna==

At this point the link to this resource is this: http://xxxxxxxxxxxx/L3N0b3JhZ2UvZW11bGF0ZWQvMC9Nb3ZpZXMvVGhlIE1vdW50YWluLm1wNA==

When an external request device requests the resource, the URI is as follows

/l3n0b3jhz2uvzw11bgf0zwqvmc9nb3zpzxmvvghlie1vdw50ywlulm1wna==

That is, more than the original code after the URI of a "/", if not do anything to deal with this URI "/l3n0b3jhz2uvzw11bgf0zwqvmc9nb3zpzxmvvghlie1vdw50ywlulm1wna==" Using Base64 decoding is the occurrence of bad-base64 anomaly, the first character is "/" is removed when the solution.

Android Base64 URI codec bad base-64 exception handling

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.