1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
rsaopenssl.php
См. документацию.
1<?
3{
4 //$_PRIV - secret key in PEM format
5 protected $_PRIV = '';
6
7 public function SetKeys($arKeys)
8 {
9 parent::SetKeys($arKeys);
10 $this->_PRIV = $arKeys["PRIV"];
11 }
12
13 public function LoadKeys()
14 {
15 $arKeys = unserialize(COption::GetOptionString("main", "~rsa_keys_openssl", ""), ['allowed_classes' => false]);
16 if(!is_array($arKeys))
17 return false;
18 $arKeys["PRIV"] = COption::GetOptionString("main", "~rsa_key_pem", "");
19 return $arKeys;
20 }
21
22 public function SaveKeys($arKeys)
23 {
24 $privKey = $arKeys["PRIV"];
25 unset($arKeys["PRIV"]);
26 COption::SetOptionString("main", "~rsa_keys_openssl", serialize($arKeys));
27 COption::SetOptionString("main", "~rsa_key_pem", $privKey);
28 }
29
30 public function Decrypt($data)
31 {
32 $key = openssl_pkey_get_private($this->_PRIV);
33
34 $out = '';
35 $blocks = explode(' ', $data);
36 foreach($blocks as $block)
37 {
38 $out1 = '';
39 openssl_private_decrypt(strrev(base64_decode($block)), $out1, $key, OPENSSL_NO_PADDING);
40 $out1 = strrev($out1);
41 $out .= $out1;
42 }
43 $out = rtrim($out);
44
45 return $out;
46 }
47
48 public function Keygen($keylen=false)
49 {
50 if($keylen === false)
51 $keylen = 1024;
52 else
53 $keylen = intval($keylen);
54
55 $fname = $_SERVER["DOCUMENT_ROOT"]."/bitrix/tmp/openssl.cnf";
56 if(!file_exists($fname))
57 {
58 CheckDirPath($fname);
59 file_put_contents($fname, '');
60 }
61
62 $keys = openssl_pkey_new(array(
63 "private_key_type"=>OPENSSL_KEYTYPE_RSA,
64 "private_key_bits"=>$keylen,
65 "config" => $fname,
66 ));
67
68 if($keys)
69 {
70 openssl_pkey_export($keys, $privkey, null, array("config" => $fname));
71 $k = self::get_openssl_key_details($privkey);
72
73 if(is_array($k))
74 {
75 return array(
76 "M" => base64_encode(strrev($k['n'])),
77 "E" => base64_encode(strrev($k['e'])),
78 "D" => base64_encode(strrev($k['d'])),
79 "PRIV" => $privkey,
80 "chunk" => $keylen/8,
81 );
82 }
83 }
84 return false;
85 }
86
87 private static function get_openssl_key_details($key)
88 {
89 //PEM to DER
90 $lines = explode("\n", trim($key));
91 unset($lines[count($lines)-1]);
92 unset($lines[0]);
93 $der = implode('', $lines);
94 $der = base64_decode($der);
95
96 //DER is in ASN.1 notation
97 $body = new CASNReader();
98 $body->Read($der);
99 $bodyItems = $body->GetSequence();
100
101 if(!empty($bodyItems))
102 {
103 if(is_object($bodyItems[1]) && is_object($bodyItems[2]) && is_object($bodyItems[3] ?? null))
104 {
105 $n = $bodyItems[1]->GetValue();
106 $e = $bodyItems[2]->GetValue();
107 $d = $bodyItems[3]->GetValue();
108
109 return array("n"=>$n, "e"=>$e, "d"=>$d);
110 }
111 elseif(is_object($bodyItems[2]))
112 {
113 $body = new CASNReader();
114 $body->Read($bodyItems[2]->GetValue());
115 $bodyItems = $body->GetSequence();
116
117 if(is_object($bodyItems[1]) && is_object($bodyItems[2]) && is_object($bodyItems[3]))
118 {
119 $n = $bodyItems[1]->GetValue();
120 $e = $bodyItems[2]->GetValue();
121 $d = $bodyItems[3]->GetValue();
122
123 return array("n"=>$n, "e"=>$e, "d"=>$d);
124 }
125 }
126 }
127 return false;
128 }
129}
130?>
Определения asn.php:3
Decrypt($data)
Определения rsaopenssl.php:30
$_PRIV
Определения rsaopenssl.php:5
SetKeys($arKeys)
Определения rsaopenssl.php:7
LoadKeys()
Определения rsaopenssl.php:13
Keygen($keylen=false)
Определения rsaopenssl.php:48
SaveKeys($arKeys)
Определения rsaopenssl.php:22
Определения rsasecurity.php:6
$data['IS_AVAILABLE']
Определения .description.php:13
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$_SERVER["DOCUMENT_ROOT"]
Определения cron_frame.php:9
CheckDirPath($path)
Определения tools.php:2707
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
if(empty($signedUserToken)) $key
Определения quickway.php:257
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"
Определения waybill.php:936
$k
Определения template_pdf.php:567
$n
Определения update_log.php:107