Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / June 2006

Tip: Looking for answers? Try searching our database.

How to figure out if data is base64encoded.

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jeremy Chapman - 28 Jun 2006 00:25 GMT
Is there some way to programatically tell if a string is base64 encoded?
Carl Daniel [VC++ MVP] - 28 Jun 2006 02:52 GMT
> Is there some way to programatically tell if a string is base64
> encoded?

In general, no.

However, if a string contains only the base64 characrter set [a-zA-Z0-9+/],
ends in 0, 1 or 2 equals signs ('=') and is a multiple of 4 characters in
total length, then it is a valid base64 encoding of something.  Of course,
that could occur completely by coincidence - the string "c3U=" is a valid
Base64 string, but it's not the encoding of anything particularly useful.

-cd
William Stacey [MVP] - 28 Jun 2006 03:34 GMT
I think the easiest and fastest way is to just try and decode it and catch
falure.  If it fails, it is not base64 or is invalid base64 for some reason.
Then you can tell in 1 pass.  If you try to walk it first just see if it is
valid, you end up with 2 passes (1 for the test and 1 for the actual
decode) - so IMO, it is not worth it anyway.

Signature

William Stacey [MVP]

| Is there some way to programatically tell if a string is base64 encoded?

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.