Skip to content

Instantly share code, notes, and snippets.

View srsbiz's full-sized avatar

Radosław Kowalewski srsbiz

View GitHub Profile
@srsbiz
srsbiz / hexit.php
Last active December 1, 2022 04:59
Web hex dumper, with colors
<?php
header('Content-Type: text/html; charset=utf-8');
define('POST_MAX_LENGTH', 4096);
if (!isset($_POST['txt'])) {
$txt = "<?php\necho 'Hello World!';\n?>";
} elseif(strlen($_POST['txt']) > POST_MAX_LENGTH) {
$txt = substr($_POST['txt'], 0, POST_MAX_LENGTH);
} else {
$txt = $_POST['txt'];
@srsbiz
srsbiz / gist:8373451ed3450c0548c3
Last active December 24, 2022 15:01
php AES-128-CBC mcrypt & openssl
<?php
function encrypt_mcrypt($msg, $key, $iv = null) {
$iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC);
if (!$iv) {
$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
}
$pad = $iv_size - (strlen($msg) % $iv_size);
$msg .= str_repeat(chr($pad), $pad);
$encryptedMessage = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $msg, MCRYPT_MODE_CBC, $iv);
return base64_encode($iv . $encryptedMessage);