Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
Encryption.php
1<?php
2
4
9final class Encryption
10{
11 public static function encrypt(string $str, ?string $salt = null): string
12 {
13 $key = $salt ?? \COption::GetOptionString('main', 'pwdhashadd', 'ldap');
14 $key1 = self::binMd5($key);
15 $res = '';
16 while ($str)
17 {
18 $m = mb_substr($str, 0, 16, 'ASCII');
19 $str = mb_substr($str, 16, mb_strlen($str, 'ASCII') - 16, 'ASCII');
20 $res .= self::byteXor($m, $key1, 16);
21 $key1 = self::binMd5($key . $key1 . $m);
22 }
23 return base64_encode($res);
24 }
25
26 public static function decrypt(string $str, ?string $salt = null): string
27 {
28 $key = $salt ?? \COption::GetOptionString('main', 'pwdhashadd', 'ldap');
29 $key1 = self::binMd5($key);
30 $str = base64_decode($str);
31 $res = '';
32 while ($str)
33 {
34 $m = mb_substr($str, 0, 16, 'ASCII');
35 $str = mb_substr($str, 16, mb_strlen($str, 'ASCII') - 16, 'ASCII');
36
37 $m = self::byteXor($m, $key1, 16);
38 $res .= $m;
39 $key1 = self::binMd5($key . $key1 . $m);
40 }
41 return $res;
42 }
43
50 public static function byteXor($a, $b, $l)
51 {
52 $c = '';
53 for ($i = 0; $i < $l; $i++)
54 {
55 $c .= $a[$i] ^ $b[$i];
56 }
57 return $c;
58 }
59
64 public static function binMd5($val)
65 {
66 return pack('H*', md5($val));
67 }
68}
static decrypt(string $str, ?string $salt=null)
static encrypt(string $str, ?string $salt=null)