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.



Your result can be seen below.

Result of php executing





Full code of 1224.php

  1. <?php
  2.  
  3. // 加密函数
  4. function encryptText($text, $key) {
  5.     $method = "AES-256-CBC";
  6.     $iv_length = openssl_cipher_iv_length($method);
  7.     $iv = openssl_random_pseudo_bytes($iv_length);
  8.     $encrypted = openssl_encrypt($text, $method, $key, OPENSSL_RAW_DATA, $iv);
  9.     $final_encrypted = $iv.$encrypted;
  10.     return base64_encode($final_encrypted);
  11. }
  12.  
  13. // 读取密钥
  14. function getKey() {
  15.     // TODO: 从配置文件、环境变量或数据库中获取密钥
  16.     return "6yh@U8oJCh6^fLLyH#BCcwyzB!Q&";
  17. }
  18.  
  19. // 访问http://域名/jm.php?text=加密内容
  20. // 文本加密
  21. if (isset($_GET['text'])) {
  22.     $text = $_GET['text'];
  23.     $key = getKey();
  24.  
  25.     // 进行文本加密
  26.     $encryptedText = encryptText($text, $key);
  27.  
  28.     // 构造 JSON 响应
  29.     $response = array(
  30.         'mgtext' => $encryptedText
  31.     );
  32.  
  33.     // 输出 JSON
  34.     header('Content-Type: application/json');
  35.     echo json_encode($response);
  36. }
  37.  
  38. ?>
  39.  
File Description
  • 1224
  • PHP Code
  • 23 Aug-2023
  • 920 Bytes
You can Share it: