1

I need a way to know if a string is Base64 encoded... any idea ?

thanks

Arutha
  • 26,088
  • 26
  • 67
  • 80
  • take a look at this answer http://stackoverflow.com/questions/1677497/guessing-the-encoding-of-text-represented-as-byte-in-java/1678810#1678810 – Boris Pavlović Oct 22 '10 at 07:47

2 Answers2

4

The string length hast to be a multiple of 4 and only the following characters are allowed A-Z, a-z, 0-9 *+, */ and = as padding character (only at the end)

phihag
  • 278,196
  • 72
  • 453
  • 469
Nikolaus Gradwohl
  • 19,708
  • 3
  • 45
  • 61
4

IMHO you need to try to decode it, and if it fails - it is not encoded.

There are many Base64 decoders for Java, here are some:

sun.misc.BASE64Decoder

Apache codec

http://migbase64.sourceforge.net/

http://www.source-code.biz/base64coder/java/

Alex Abdugafarov
  • 6,112
  • 7
  • 35
  • 59