1C-Bitrix
25.700.0
Загрузка...
Поиск...
Не найдено
hmacalgorithm.php
См. документацию.
1
<?php
2
namespace
Bitrix\Main\Security\Sign;
3
4
use Bitrix\Main\ArgumentOutOfRangeException;
5
use Bitrix\Main\ArgumentTypeException;
6
12
class
HmacAlgorithm
13
extends
SigningAlgorithm
14
{
15
// ToDo: need option here?
16
// Default hashing algorithm used by HMAC
17
protected
$hashAlgorithm
=
'sha256'
;
18
19
26
public
function
__construct
(
$hashAlgorithm
=
null
)
27
{
28
if
(
$hashAlgorithm
)
29
$this->
setHashAlgorithm
(
$hashAlgorithm
);
30
}
31
39
public
function
setHashAlgorithm
(
$hashAlgorithm
)
40
{
41
if
(!in_array(
$hashAlgorithm
, hash_algos()))
42
throw
new
ArgumentOutOfRangeException
(
'hashAlgorithm'
, hash_algos());
43
44
$this->hashAlgorithm =
$hashAlgorithm
;
45
return
$this;
46
}
47
53
public
function
getHashAlgorithm
()
54
{
55
return
$this->hashAlgorithm
;
56
}
57
65
public
function
getSignature
($value,
$key
)
66
{
67
return
hash_hmac($this->hashAlgorithm, $value,
$key
,
true
);
68
}
69
78
public
function
verify
($value,
$key
, $sig)
79
{
80
return
$this->
compareStrings
(
81
$this->
getSignature
($value,
$key
),
82
$sig
83
);
84
}
85
99
protected
function
compareStrings
($expected, $actual)
100
{
101
if
(!is_string($expected))
102
{
103
throw
new
ArgumentTypeException
(
'expected'
,
'string'
);
104
}
105
106
if
(!is_string($actual))
107
{
108
throw
new
ArgumentTypeException
(
'actual'
,
'string'
);
109
}
110
111
$lenExpected = strlen($expected);
112
$lenActual = strlen($actual);
113
114
$status
= $lenExpected ^ $lenActual;
115
$len = min($lenExpected, $lenActual);
116
for
(
$i
= 0;
$i
< $len;
$i
++)
117
{
118
$status
|= ord($expected[
$i
]) ^ ord($actual[
$i
]);
119
}
120
121
return
$status
=== 0;
122
}
123
124
}
Bitrix\Main\ArgumentOutOfRangeException
Определения
ArgumentOutOfRangeException.php:9
Bitrix\Main\ArgumentTypeException
Определения
ArgumentTypeException.php:9
Bitrix\Main\Security\Sign\HmacAlgorithm
Определения
hmacalgorithm.php:14
Bitrix\Main\Security\Sign\HmacAlgorithm\__construct
__construct($hashAlgorithm=null)
Определения
hmacalgorithm.php:26
Bitrix\Main\Security\Sign\HmacAlgorithm\getSignature
getSignature($value, $key)
Определения
hmacalgorithm.php:65
Bitrix\Main\Security\Sign\HmacAlgorithm\$hashAlgorithm
$hashAlgorithm
Определения
hmacalgorithm.php:17
Bitrix\Main\Security\Sign\HmacAlgorithm\setHashAlgorithm
setHashAlgorithm($hashAlgorithm)
Определения
hmacalgorithm.php:39
Bitrix\Main\Security\Sign\HmacAlgorithm\compareStrings
compareStrings($expected, $actual)
Определения
hmacalgorithm.php:99
Bitrix\Main\Security\Sign\HmacAlgorithm\verify
verify($value, $key, $sig)
Определения
hmacalgorithm.php:78
Bitrix\Main\Security\Sign\HmacAlgorithm\getHashAlgorithm
getHashAlgorithm()
Определения
hmacalgorithm.php:53
Bitrix\Main\Security\Sign\SigningAlgorithm
Определения
signingalgorithm.php:12
$status
$status
Определения
session.php:10
$key
if(empty($signedUserToken)) $key
Определения
quickway.php:257
$i
$i
Определения
factura.php:643
bitrix
modules
main
lib
security
sign
hmacalgorithm.php
Создано системой
1.14.0