File manager - Edit - /home/autoph/public_html/connectv1/cfg/cipher.php
Back
<?php class AES256Encryption { public const BLOCK_SIZE = 8; public const IV_LENGTH = 16; public const CIPHER = 'AES256'; public static function generateIv(bool $allowLessSecure = false): string { $success = false; $random = openssl_random_pseudo_bytes(openssl_cipher_iv_length(static::CIPHER)); if (!$success) { if (function_exists('sodium_randombytes_random16')) { $random = sodium_randombytes_random16(); } else { try { $random = random_bytes(static::IV_LENGTH); } catch (Exception $e) { if ($allowLessSecure) { $permitted_chars = implode( '', array_merge( range('A', 'z'), range(0, 9), str_split('~!@#$%&*()-=+{};:"<>,.?/\'') ) ); $random = ''; for ($i = 0; $i < static::IV_LENGTH; $i++) { $random .= $permitted_chars[mt_rand(0, (static::IV_LENGTH) - 1)]; } } else { throw new RuntimeException('Unable to generate initialization vector (IV)'); } } } } return $random; } protected static function getPaddedText(string $plainText): string { $stringLength = strlen($plainText); if ($stringLength % static::BLOCK_SIZE) { $plainText = str_pad($plainText, $stringLength + static::BLOCK_SIZE - $stringLength % static::BLOCK_SIZE, "\0"); } return $plainText; } public static function encrypt(string $plainText, string $key, string $iv): string { $plainText = static::getPaddedText($plainText); return base64_encode(openssl_encrypt($plainText, static::CIPHER, $key, OPENSSL_RAW_DATA, $iv)); } public static function decrypt(string $encryptedText, string $key, string $iv): string { return openssl_decrypt(base64_decode($encryptedText), static::CIPHER, $key, OPENSSL_RAW_DATA, $iv); } } ?>
| ver. 1.4 |
.
| PHP 7.3.33 | Generation time: 0 |
proxy
|
phpinfo
|
Settings