Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
cryptofield.php
1
<?php
2
namespace
Bitrix\Socialservices\EncryptedToken
;
3
4
use
Bitrix\Main\Security\SecurityException
;
5
6
class
CryptoField
extends
\Bitrix\Main\ORM\Fields\CryptoField
7
{
8
protected
$encryptionComplete
=
false
;
9
protected
$ivLength
;
10
11
public
function
__construct
(
$name
, $parameters = array())
12
{
13
if
(isset($parameters[
'encryption_complete'
]))
14
{
15
$this->encryptionComplete = !!$parameters[
'encryption_complete'
];
16
unset($parameters[
'encryption_complete'
]);
17
}
18
if
(!static::cryptoAvailable())
19
{
20
$parameters[
'crypto_enabled'
] =
false
;
21
}
22
parent::__construct(
$name
, $parameters);
23
$this->ivLength = openssl_cipher_iv_length(
'aes-256-ctr'
);
24
}
25
26
public
static
function
cryptoAvailable
($key =
''
)
27
{
28
if
(!\
Bitrix
\Main\
Config
\Option::get(
"socialservices"
,
"allow_encrypted_tokens"
,
false
))
29
return
false
;
30
31
return
parent::cryptoAvailable($key);
32
}
33
34
public
function
decrypt
($data)
35
{
36
if
($this->encryptionComplete)
37
return
parent::decrypt($data);
38
39
if
($data ==
''
)
40
return
$data;
41
42
try
43
{
44
$value = base64_decode($data);
45
if
(
false
=== $value)
// not base64 decoded so not encrypted
46
return
$data;
47
48
if
(mb_strlen($value,
'latin1'
) <= $this->ivLength)
// too short to be encrypted
49
return
$data;
50
51
$value = static::$cipher->decrypt($value, $this->cryptoKey);
52
return
$value;
53
}
54
catch
(
SecurityException
$e)
55
{
56
return
$data;
57
}
58
}
59
}
Bitrix\Main\ORM\Fields\CryptoField
Definition
cryptofield.php:14
Bitrix\Main\ORM\Fields\Field\$name
$name
Definition
field.php:27
Bitrix\Main\Security\SecurityException
Definition
securityexception.php:5
Bitrix\Socialservices\EncryptedToken\CryptoField
Definition
cryptofield.php:7
Bitrix\Socialservices\EncryptedToken\CryptoField\cryptoAvailable
static cryptoAvailable($key='')
Definition
cryptofield.php:26
Bitrix\Socialservices\EncryptedToken\CryptoField\$ivLength
$ivLength
Definition
cryptofield.php:9
Bitrix\Socialservices\EncryptedToken\CryptoField\$encryptionComplete
$encryptionComplete
Definition
cryptofield.php:8
Bitrix\Socialservices\EncryptedToken\CryptoField\decrypt
decrypt($data)
Definition
cryptofield.php:34
Bitrix\Socialservices\EncryptedToken\CryptoField\__construct
__construct($name, $parameters=array())
Definition
cryptofield.php:11
Bitrix\Main\Config
Definition
configuration.php:2
Bitrix\Socialservices\EncryptedToken
Definition
agent.php:2
Bitrix
modules
socialservices
lib
encryptedtoken
cryptofield.php
Создано системой
1.10.0