nfldb_m2
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revision | |||
| nfldb_m2 [2026/06/01 01:00] – admin | nfldb_m2 [2026/06/02 14:18] (current) – admin | ||
|---|---|---|---|
| Line 21: | Line 21: | ||
| $sql = " | $sql = " | ||
| | | ||
| - | network first for start_url | + | encryption |
| + | |||
| + | | ||
| if (event.request.mode === ' | if (event.request.mode === ' | ||
| event.respondWith( | event.respondWith( | ||
| Line 41: | Line 43: | ||
| }) | }) | ||
| ); | ); | ||
| + | } | ||
| + | | ||
| + | javascriptasync function encryptData(plaintext, | ||
| + | // 1. Convert hex key to byte array | ||
| + | const keyBuffer = new Uint8Array(hexKey.match(/ | ||
| + | | ||
| + | // 2. Import the raw key into Web Crypto API | ||
| + | const cryptoKey = await crypto.subtle.importKey( | ||
| + | " | ||
| + | ); | ||
| + | |||
| + | // 3. Generate a random 16-byte initialization vector (IV) | ||
| + | const iv = crypto.getRandomValues(new Uint8Array(16)); | ||
| + | const encoder = new TextEncoder(); | ||
| + | const encodedPlaintext = encoder.encode(plaintext); | ||
| + | |||
| + | // 4. Encrypt the data | ||
| + | const ciphertextBuffer = await crypto.subtle.encrypt( | ||
| + | { name: " | ||
| + | ); | ||
| + | |||
| + | // 5. Convert IV and Ciphertext to Base64 | ||
| + | const ivBase64 = btoa(String.fromCharCode(...iv)); | ||
| + | const ciphertextBase64 = btoa(String.fromCharCode(...new Uint8Array(ciphertextBuffer))); | ||
| + | |||
| + | // 6. Combine them with a colon separator for transmission | ||
| + | return `${ivBase64}: | ||
| + | } | ||
| + | |||
| + | // Execution Example: | ||
| + | encryptData(" | ||
| + | .then(encryptedString => console.log(" | ||
| + | Use code with caution.🐘 PHP Decryption (Server)The PHP script accepts the composite Base64 string, splits it back into the individual IV and ciphertext segments, and decrypts it using the built-in OpenSSL library.php<? | ||
| + | |||
| + | function decryptData($encryptedString, | ||
| + | // 1. Convert hex key back to binary | ||
| + | $key = hex2bin($hexKey); | ||
| + | |||
| + | // 2. Split the incoming payload into IV and Ciphertext components | ||
| + | $parts = explode(':', | ||
| + | if (count($parts) !== 2) { | ||
| + | return false; // Invalid payload structure | ||
| + | } | ||
| + | |||
| + | $iv = base64_decode($parts[0]); | ||
| + | $ciphertext = base64_decode($parts[1]); | ||
| + | |||
| + | // 3. Decrypt using native OpenSSL | ||
| + | $decrypted = openssl_decrypt( | ||
| + | $ciphertext, | ||
| + | ' | ||
| + | $key, | ||
| + | OPENSSL_RAW_DATA, | ||
| + | $iv | ||
| + | ); | ||
| + | |||
| + | return $decrypted; | ||
| + | } | ||
| + | |||
| + | // Execution Example: | ||
| + | $hexKey = " | ||
| + | $receivedPayload = $_POST[' | ||
| + | |||
| + | $decryptedMessage = decryptData($receivedPayload, | ||
| + | |||
| + | if ($decryptedMessage !== false) { | ||
| + | echo " | ||
| + | } else { | ||
| + | echo " | ||
| } | } | ||
nfldb_m2.1780275659.txt.gz · Last modified: 2026/06/01 01:00 by admin