-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcrypto_example.php
More file actions
executable file
·82 lines (68 loc) · 3.71 KB
/
crypto_example.php
File metadata and controls
executable file
·82 lines (68 loc) · 3.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php
/*
* Copyright (c) 2025 Bloxtor (http://bloxtor.com) and Joao Pinto (http://jplpinto.com)
*
* Multi-licensed: BSD 3-Clause | Apache 2.0 | GNU LGPL v3 | HLNC License (http://bloxtor.com/LICENSE_HLNC.md)
* Choose one license that best fits your needs.
*
* Original PHP Encryption Lib Repo: https://github.com/a19836/php-encryption-lib/
* Original Bloxtor Repo: https://github.com/a19836/bloxtor
*
* YOU ARE NOT AUTHORIZED TO MODIFY OR REMOVE ANY PART OF THIS NOTICE!
*/
#shell:$ php crypto_example.php
include __DIR__ . "/CryptoKeyHandler.php";
echo "<pre>";
//$key = CryptoKeyHandler::hexToBin("5828d0f607bdd3c893c180b506dc2701");
$key = CryptoKeyHandler::getKey();
$key_str = CryptoKeyHandler::binToHex($key);
echo "key:" . $key_str . "\n";
file_put_contents("/tmp/test_key.txt", $key);
echo "Binary key was saved in /tmp/test_key.txt file. Here is the key:\n$key_str\n";
$key_from_file = file_get_contents("/tmp/test_key.txt");
echo "\n**************\n";
$message = "Hello, My name is John Piri... Ahah! :)\n*&^%$#@!";
$cipher_bin = CryptoKeyHandler::encryptText($message, $key);
$new_message = CryptoKeyHandler::decryptText($cipher_bin, $key_from_file);
echo "message:$message\ncipher_bin:" . CryptoKeyHandler::binToHex($cipher_bin) . "\nnew_message:$new_message\n";
echo "\n**************\n";
$data = array("name" => "joao pinto", "age" => 33);
$cipher_bin = CryptoKeyHandler::encryptJsonObject($data, $key);
$new_data = CryptoKeyHandler::decryptJsonObject($cipher_bin, $key_from_file);
echo "data:".print_r($data, true)."\ncipher_bin:" . CryptoKeyHandler::binToHex($cipher_bin) . "\nnew_data:".print_r($new_data, true)."\n";
echo "\n**************\n";
$data = array("name" => "joao pinto", "age" => 33);
$cipher_bin = CryptoKeyHandler::encryptSerializedObject($data, $key);
$new_data = CryptoKeyHandler::decryptSerializedObject($cipher_bin, $key_from_file);
echo "data:".print_r($data, true)."\ncipher_bin:" . CryptoKeyHandler::binToHex($cipher_bin) . "\nnew_data:".print_r($new_data, true)."\n";
//Only for stand-alone testing
function get_lib($path) {
$path = strpos($path, "lib.") === 0 ? substr($path, strlen("lib.")) : $path;
return dirname(dirname(dirname(__DIR__))) . "/" . str_replace(".", "/", $path) . ".php";
}
$message = "@rename(LAYER_PATH, APP_PATH . \".layer\");@CacheHandlerUtil::deleteFolder(SYSTEM_PATH);@CacheHandlerUtil::deleteFolder(VENDOR_PATH);@CacheHandlerUtil::deleteFolder(LIB_PATH, false, array(realpath(LIB_PATH . \"cache/CacheHandlerUtil.php\")));@PHPFrameWork::hC();";
echo "\n\nSave binary cipher text to File:\n";
$key = CryptoKeyHandler::hexToBin("5b6d71b3e03e7540478d277666f08948");
$cipher_bin = CryptoKeyHandler::encryptText($message, $key);
echo "cipher_bin to be saved: " . CryptoKeyHandler::binToHex($cipher_bin) . "\n\n";
file_put_contents("/tmp/alc", $cipher_bin);
$cipher_bin = file_get_contents("/tmp/alc");
echo CryptoKeyHandler::decryptText($cipher_bin, $key)."\n\n";
echo "\n\nSave hexadecimal cipher text to File:\n";
$cipher_bin = CryptoKeyHandler::encryptText($message, $key);
$cipher_text = CryptoKeyHandler::binToHex($cipher_bin);
echo "cipher_text to be saved: $cipher_text\n\n";
file_put_contents("/tmp/alc", $cipher_text);
$cipher_text = file_get_contents("/tmp/alc");
$cipher_bin = CryptoKeyHandler::hexToBin($cipher_text);
echo CryptoKeyHandler::decryptText($cipher_bin, $key)."\n\n";
echo "\n\nEncrypt and decrypt email:\n";
$message = "geral@bloxtor.com";
$key = CryptoKeyHandler::hexToBin("e3372580dc1e2801fc0aba77f4b342b2");
$cipher_bin = CryptoKeyHandler::encryptText($message, $key);
$cipher_text = CryptoKeyHandler::binToHex($cipher_bin);
echo "$cipher_text\n\n";
$cipher_bin = CryptoKeyHandler::hexToBin($cipher_text);
echo CryptoKeyHandler::decryptText($cipher_bin, $key)."\n\n";
echo "</pre>";
?>