ParagonIE_Sodium_Core_Util::bin2hex() public WP 1.0
Convert a binary string into a hexadecimal string without cache-timing leaks
{} It's a method of the class: ParagonIE_Sodium_Core_Util{}
No Hooks.
Return
String
. Null. Nothing.
Usage
$result = ParagonIE_Sodium_Core_Util::bin2hex( $binaryString );
- $binaryString(string) (required)
- (raw binary)
Code of ParagonIE_Sodium_Core_Util::bin2hex() ParagonIE Sodium Core Util::bin2hex WP 5.7
public static function bin2hex($binaryString)
{
/* Type checks: */
if (!is_string($binaryString)) {
throw new TypeError('Argument 1 must be a string, ' . gettype($binaryString) . ' given.');
}
$hex = '';
$len = self::strlen($binaryString);
for ($i = 0; $i < $len; ++$i) {
/** @var array<int, int> $chunk */
$chunk = unpack('C', $binaryString[$i]);
/** @var int $c */
$c = $chunk[1] & 0xf;
/** @var int $b */
$b = $chunk[1] >> 4;
$hex .= pack(
'CC',
(87 + $b + ((($b - 10) >> 8) & ~38)),
(87 + $c + ((($c - 10) >> 8) & ~38))
);
}
return $hex;
}