Skip to content

Commit 43c2a2e

Browse files
authored
Update index.php
1 parent 3757b67 commit 43c2a2e

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

public/index.php

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,48 @@ function cleanArray($didYouMeans){
4141

4242

4343

44+
$pub_key_file = __DIR__ . ''. \DIRECTORY_SEPARATOR. '..' . \DIRECTORY_SEPARATOR. '.api-keys'. \DIRECTORY_SEPARATOR. 'pub.key';
45+
$priv_key_file = __DIR__ . ''. \DIRECTORY_SEPARATOR. '..'. \DIRECTORY_SEPARATOR. '.api-keys'. \DIRECTORY_SEPARATOR. 'priv.key';
46+
47+
if(!is_dir(dirname($pub_key_file))){
48+
mkdir(dirname($pub_key_file), 0755, true);
49+
}
50+
51+
if(!is_dir(dirname($priv_key_file))){
52+
mkdir(dirname($priv_key_file), 0755, true);
53+
}
54+
55+
if(!file_exists($pub_key_file) || !file_exists($priv_key_file) ){
56+
$config = array(
57+
"digest_alg" => "sha512",
58+
"private_key_bits" => 4096,
59+
"private_key_type" => \OPENSSL_KEYTYPE_RSA,
60+
);
61+
62+
// Create the private and public key
63+
$res = openssl_pkey_new($config);
64+
65+
// Extract the private key from $res to $privKey
66+
openssl_pkey_export($res, $privKey);
67+
68+
// Extract the public key from $res to $pubKey
69+
$pubKey = openssl_pkey_get_details($res);
70+
$pubKey = $pubKey["key"];
71+
72+
73+
file_put_contents($pub_key_file, $pubKey);
74+
file_put_contents($priv_key_file, $privKey);
75+
//$data = 'plaintext data goes here';
76+
77+
// Encrypt the data to $encrypted using the public key
78+
//openssl_public_encrypt($data, $encrypted, $pubKey);
79+
80+
// Decrypt the data using the private key and store the results in $decrypted
81+
//openssl_private_decrypt($encrypted, $decrypted, $privKey);
82+
}
83+
84+
85+
4486
$per_page = 25;
4587

4688
$someDirs=[
@@ -179,6 +221,10 @@ function cleanArray($didYouMeans){
179221
$code = (new \Nette\PhpGenerator\PsrPrinter)->printFile($FileAll);
180222

181223

224+
$code = false === strpos($code, base64_decode('X19oYWx0X2NvbXBpbGVyKCk7'))
225+
? $loader->sign($code, file_get_contents($priv_key_file), 'X19oYWx0X2NvbXBpbGVyKCk7')
226+
: $code;
227+
182228
if((isset($_SERVER['HTTP_X_SOURCE_ENCODING']) && 'b64' === $_SERVER['HTTP_X_SOURCE_ENCODING'])
183229
||
184230
(isset($_GET['source-encoding']) && 'b64' === $_GET['source-encoding'] )
@@ -267,6 +313,13 @@ function cleanArray($didYouMeans){
267313
}
268314

269315

316+
317+
$outPut = false === strpos($outPut, base64_decode('X19oYWx0X2NvbXBpbGVyKCk7'))
318+
? $loader->sign($outPut, file_get_contents($priv_key_file), 'X19oYWx0X2NvbXBpbGVyKCk7')
319+
: $outPut;
320+
321+
322+
270323
if((isset($_SERVER['HTTP_X_SOURCE_ENCODING']) && 'b64' === $_SERVER['HTTP_X_SOURCE_ENCODING'])
271324
||
272325
(isset($_GET['source-encoding']) && 'b64' === $_GET['source-encoding'] )

0 commit comments

Comments
 (0)