(PHP 7 >= 7.2.0, PHP 8)
sodium_base642bin — Décode une chaîne encodée en base64 en binaire brut.
$string, int $id, string $ignore = ""): stringConvertit une chaîne encodée en base64 en binaire brut. Contrairement à base64_decode(), sodium_base642bin() est en temps constant (une propriété importante pour tout code qui manipule des entrées cryptographiques, telles que des textes en clair ou des clés) et prend en charge plusieurs jeux de caractères.
stringstring; Chaîne encodée.
idSODIUM_BASE64_VARIANT_ORIGINAL pour le standard (A-Za-z0-9/\+)
encodé en base64.
SODIUM_BASE64_VARIANT_ORIGINAL_NO_PADDING pour le standard (A-Za-z0-9/\+)
encodé en base64, sans caractères de remplissage =.
SODIUM_BASE64_VARIANT_URLSAFE pour l'encodage Base64 sûr pour les URL (A-Za-z0-9\-_).
SODIUM_BASE64_VARIANT_URLSAFE_NO_PADDING pour l'encodage Base64 sûr pour les URL (A-Za-z0-9\-_),
sans caractères de remplissage =.
ignoreLes caractères à ignorer lors du décodage (par exemple, les caractères d'espacement).
La chaîne décodée.
Exemple #1 Exemple de sodium_base642bin()
<?php
$string = 'VGhpcyBpcyBhbiBlbmNvZGVkIHN0cmluZw==';
echo sodium_base642bin($string, SODIUM_BASE64_VARIANT_ORIGINAL);
?>L'exemple ci-dessus va afficher :
This is an encoded string
Exemple #2 Exemple du paramètre id
<?php
var_dump(sodium_bin2hex(sodium_base642bin('rrZ5j+9OUYT/O1WWr3U0hw==', SODIUM_BASE64_VARIANT_ORIGINAL)));
var_dump(sodium_bin2hex(sodium_base642bin('rrZ5j+9OUYT/O1WWr3U0hw', SODIUM_BASE64_VARIANT_ORIGINAL_NO_PADDING)));
var_dump(sodium_bin2hex(sodium_base642bin('rrZ5j-9OUYT_O1WWr3U0hw==', SODIUM_BASE64_VARIANT_URLSAFE)));
var_dump(sodium_bin2hex(sodium_base642bin('rrZ5j-9OUYT_O1WWr3U0hw', SODIUM_BASE64_VARIANT_URLSAFE_NO_PADDING)));
?>L'exemple ci-dessus va afficher :
string(32) "aeb6798fef4e5184ff3b5596af753487" string(32) "aeb6798fef4e5184ff3b5596af753487" string(32) "aeb6798fef4e5184ff3b5596af753487" string(32) "aeb6798fef4e5184ff3b5596af753487"
Exemple #3 Exemple du paramètre ignore
<?php
$string = <<<'STR'
VGhpcyBpcy
BhbiBlbmNv
ZGVkIHN0cm
luZw==
STR;
var_dump(sodium_base642bin($string, SODIUM_BASE64_VARIANT_ORIGINAL, " \r\n"));
?>L'exemple ci-dessus va afficher :
string(25) "This is an encoded string"