1224 - PHP Online
Form of PHP Sandbox
Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php
in the places where the PHP script should be executed.
Result of php executing
Full code of 1224.php
- <?php
- // 加密函数
- function encryptText($text, $key) {
- $method = "AES-256-CBC";
- $iv_length = openssl_cipher_iv_length($method);
- $iv = openssl_random_pseudo_bytes($iv_length);
- $encrypted = openssl_encrypt($text, $method, $key, OPENSSL_RAW_DATA, $iv);
- $final_encrypted = $iv.$encrypted;
- return base64_encode($final_encrypted);
- }
- // 读取密钥
- function getKey() {
- // TODO: 从配置文件、环境变量或数据库中获取密钥
- return "6yh@U8oJCh6^fLLyH#BCcwyzB!Q&";
- }
- // 访问http://域名/jm.php?text=加密内容
- // 文本加密
- if (isset($_GET['text'])) {
- $text = $_GET['text'];
- $key = getKey();
- // 进行文本加密
- $encryptedText = encryptText($text, $key);
- // 构造 JSON 响应
- $response = array(
- 'mgtext' => $encryptedText
- );
- // 输出 JSON
- header('Content-Type: application/json');
- echo json_encode($response);
- }
- ?>