Arutha
Arutha

Reputation: 26488

java string base64 encoded

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

thanks

Upvotes: 1

Views: 2881

Answers (2)

Nikolaus Gradwohl
Nikolaus Gradwohl

Reputation: 20124

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)

Upvotes: 4

Alex Abdugafarov
Alex Abdugafarov

Reputation: 6432

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/

Upvotes: 4

Related Questions