Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does this base64 string comparison in Perl fail?

Tags:

base64

perl

I am trying to compare an encode_base64('test') to the string variable containing the base64 string of 'test'. The problem is it never validates!

use MIMI::Base64 qw(encode_base64);

if (encode_base64("test") eq "dGVzdA==")
{
    print "true";
}

Am I forgetting anything?

like image 936
Bob Avatar asked Dec 02 '22 06:12

Bob


1 Answers

Here's a link to a Perlmonks page which says "Beware of the newline at the end of the encode_base64() encoded strings".

So the simple 'eq' may fail.

To suppress the newline, say encode_base64("test", "") instead.

like image 199
pavium Avatar answered Dec 24 '22 14:12

pavium