Skip to content

Instantly share code, notes, and snippets.

View chlp's full-sized avatar
🤠

Aleksei Rytikov chlp

🤠
View GitHub Profile
@chlp
chlp / replace_serialized_data.php
Created May 7, 2019 14:22
php change str_replace inside serialized data and fix it
<?php
$change_from = 'old_string';
$change_to = 'new_string_new_length';
$serialized = file_get_contents('serialized_data.txt');
$serialized = str_replace($change_from, $change_to, $serialized);
function fix_str_length($matches) {
$string = $matches[2];
$right_length = strlen($string); // yes, strlen even for UTF-8 characters, PHP wants the mem size, not the char count
return 's:' . $right_length . ':"' . $string . '";';
}
@chlp
chlp / symmetric-encode-decode.php
Created December 4, 2018 16:21
Example of usage OpenSSL symmetric encoding and decoding with AES-256-CBC on php and from command line
<?php
// ENCRYPTION
$method = 'AES-256-CBC';
$secret = 'my secret';
$key = 'test';
$hex_key = (bin2hex($key)); // example 74657374
$length = openssl_cipher_iv_length($method);
$iv = openssl_random_pseudo_bytes($length);
// $iv = hex2bin("047ed7c4aaf0069daa06b633b86aff67");
@chlp
chlp / shri.js
Last active August 29, 2015 14:24 — forked from verkholantsev/shri.js
/**
* Реализация API, не изменяйте ее
* @param {string} url
* @param {function} callback
*/
function getData(url, callback) {
var RESPONSES = {
'/countries': [
{name: 'Cameroon', continent: 'Africa'},
{name :'Fiji Islands', continent: 'Oceania'},