I have not done very extensive testing, but this seems to determine whether a string is Base64 encoded or not.

use warnings; use strict; use MIME::Base64; my $base64text = encode_base64('This is some Base64 encoded text'); my $notbase64text = 'This is text is not Base64 encoded'; print is_base64($base64text) || "\nNot Base64\n"; print is_base64($notbase64text) || "\nNot Base64\n"; sub is_base64{ #Returns the decoded data on success, undef on failure my $data = shift; return(undef) unless ($data =~ /^[A-Za-z0-9+\/=]+$/); #test for vali +d Base64 string if (length ($data)%4==0){ print "Valid Base64\n"; my $decoded = decode_base64($data); return( $decoded ); } else { print "Invalid Base64\n"; return(undef); } }

In reply to Re: Reliable way to detect base64 encoded strings by bcarroll
in thread Reliable way to detect base64 encoded strings by Rodster001

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.