indexNo.php 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>AES CBC Encryption and QR Code Generation</title>
  7. <script src="./crypto-js.min.js"></script>
  8. <script src="./qrcode.min.js"></script>
  9. <style>
  10. html,
  11. body {
  12. width: 100%;
  13. height: 98%;
  14. margin: 0;
  15. padding: 0;
  16. text-align: center;
  17. align-items: center;
  18. }
  19. </style>
  20. </head>
  21. <body>
  22. <h1>AES CBC Encryption and QR Code Generation</h1>
  23. <form method="post">
  24. <input type="text" name="userName" placeholder="User name">
  25. <br>
  26. <input type="text" name="password" placeholder="Password">
  27. <br>
  28. <br>
  29. <button type="submit" name="encryptAndGenerateQR">Encrypt & Generate QR Code</button>
  30. <button type="submit" name="UPDATEurl">UPDATEurl</button>
  31. </form>
  32. <br>
  33. <br>
  34. <div style="width: 100%; display: flex; justify-content:center">
  35. <div style="width: 256px; height: 256px; border: 1px solid black; padding: 2%" id="qrcode"></div>
  36. </div>
  37. <div id="AES_str" style="width: 89%; padding: 5%; word-break: break-all;"></div>
  38. <?php
  39. if (isset($_POST['encryptAndGenerateQR'])) {
  40. $userName = $_POST['userName'];
  41. $password = $_POST['password'];
  42. if ($userName == "UPDATEurl") {
  43. $encryptedText = $userName . ";" . $password . ";";
  44. } else {
  45. // Encryption
  46. $plaintext = "u_name@" . $userName . ";" . "u_password@" . $password . ";";
  47. $key = "A123061230612306";
  48. $iv = "0000000000000000";
  49. $encryptedText = openssl_encrypt($plaintext, 'AES-128-CBC', $key, 0, $iv);
  50. }
  51. // echo "<br>" . $encryptedText . "<br>";
  52. // Generate QR Code
  53. echo '<script>
  54. var qr = new QRCode(document.getElementById("qrcode"), {
  55. text: "' . $encryptedText . '",
  56. width: 256,
  57. height: 256,
  58. colorDark: "#000000",
  59. colorLight: "#ffffff",
  60. correctLevel: QRCode.CorrectLevel.H
  61. });
  62. document.getElementById("AES_str").innerHTML = "' . $encryptedText . '";
  63. </script>';
  64. } else if (isset($_POST['UPDATEurl'])) {
  65. $encryptedText = "UPDATEurl;" . $_POST['password'] . ";";
  66. echo '<script>
  67. var qr = new QRCode(document.getElementById("qrcode"), {
  68. text: "' . $encryptedText . '",
  69. width: 256,
  70. height: 256,
  71. colorDark: "#000000",
  72. colorLight: "#ffffff",
  73. correctLevel: QRCode.CorrectLevel.H
  74. });
  75. document.getElementById("AES_str").innerHTML = "' . $encryptedText . '";
  76. </script>';
  77. }
  78. ?>
  79. </body>
  80. </html>