Why does Str_repeat,str_pad use CHR to return ASCII code in some cryptographic algorithms in PHP?
Consider the following encryption algorithm:
function Custom_hmac ($algo, $data, $key, $raw _output = False)
{
$algo = Strtolower ($algo);
$pack = ' H '. strlen ($algo (' Test '));
$size = 64;
$opad = Str_repeat (Chr (0x5C), $size);
$ipad = Str_repeat (Chr (0x36), $size);
This code, please explain in detail
if (strlen ($key) > $size) {
$key = Str_pad (Pack ($pack, $algo ($key)), $size, Chr (0x00));
} else {
$key = Str_pad ($key, $size, Chr (0x00));
}
for ($i = 0; $i < strlen ($key)-1; $i + +) {
$opad [$i] = $opad [$i] ^ $key [$i];
$ipad [$i] = $ipad [$i] ^ $key [$i];
}//, that's not quite clear.
$output = $algo ($opad. Pack ($pack, $algo ($ipad. $data)));
Return ($raw _output)? Pack ($pack, $output): $output;
}
------to solve the idea----------------------
Str_pad string to a specified length with specified characters
It's $size in here.
The same length, there is no need to determine whether the element exists in the following loop