2013-03-13 64 views
-1

如何獲得MIME :: Base64 :: decode()中的功能,如在php base64_decode函數中嚴格參數?Perl嚴格decode_base64

+0

什麼是你的代碼? – 2013-03-13 19:53:25

+0

的[CPAN頁](http://search.cpan.org/~gaas/MIME-Base64-3.13/Base64.pm)具有實施例,其只是做這個。 – 2013-03-13 19:53:45

+0

我輸入可包含損壞和Base64編碼字母不能有不匹配的數據,我需要的是函數返回布爾值false,如果它是。 – Aphex 2013-03-13 20:02:44

回答

1
my $c = '[A-Za-z0-9+/]'; 
my $strict = qr/ 
^
    (?:$c{4})*+ 
    (?:$c(?:==|$c(?:=|$c))=)?+ 
    \z 
/x; 

sub php_base64_decode { 
    return undef if $_[1] && $_[0] !~ $strict; 
    return decode_base64($_[0]); 
} 

不知道什麼PHP的base64_decode正是這麼做,所以你可能需要調整的格局中$strict

+0

那麼它似乎這是唯一的方法,但我都必須UTF8字符添加到模式:( – Aphex 2013-03-13 20:15:50

+0

@Aphex,這是沒有意義的。 – ikegami 2013-03-13 20:25:44

+0

@Aphex你的意思是沒有用base64編碼UTF8的數據? – 2013-03-14 04:53:30