海运的博客

PHP下AES CBC/CFB 256加密

发布时间:February 3, 2017 // 分类:PHP // No Comments

AES CFB加解密:

<?php
$iv = substr(md5("iv"),0,16);
$encryption_key = substr(md5("key"),0,32);
echo $encryption_key."\n";
$data = 'data';
$data = openssl_encrypt($data, 'aes-256-cfb', $encryption_key, OPENSSL_RAW_DATA|OPENSSL_ZERO_PADDING, $iv);
echo bin2hex($data) . "\r\n";

$iv = substr(md5("iv"),0,16);
$data = openssl_decrypt($data, 'aes-256-cfb', $encryption_key, OPENSSL_RAW_DATA|OPENSSL_ZERO_PADDING, $iv);
echo $data . "\r\n";
?>

AES CBC加解密:

<?php
$iv = substr(md5("iv"),0,16);
$encryption_key = substr(md5("key"),0,32);
$data = 'data';
$data = openssl_encrypt($data, 'aes-256-cbc', $encryption_key, OPENSSL_RAW_DATA, $iv);
echo bin2hex($data) . "\r\n";

$iv = substr(md5("iv"),0,16);
$data = openssl_decrypt($data, 'aes-256-cbc', $encryption_key, OPENSSL_RAW_DATA, $iv);
echo $data . "\r\n";
?>

小内存生成QQ号

发布时间:July 24, 2016 // 分类:PHP // No Comments

<?php
ini_set("memory_limit","1800M");
$count = 0;
for ($i = 10000; $i <= 300000000; $i++) {
        $count++;
        $str[] = $i;
        if (($i % 100) == 0) {
                shuffle($str);
                $a = implode("\n", $str);
                $file = mt_rand(0, 10000);
                file_put_contents('data/'.$file.'.txt', $a."\n", FILE_APPEND);
                $str = array();
        }
}
for file in `ls *.txt`;do shuf $file > $file-shuf;done
cat data/*-shuf > shuf-all.txt

PHP trim数组

发布时间:October 16, 2015 // 分类:PHP // No Comments

<?php
//方法1
function trim_array($input) {
  if (!is_array($input))
    return trim($input);
  return array_map('trim_array', $input);
}
$Array = trim_array($Array);
//方法2
function trim_value (& $value ) { 
  if (!is_array($value)) {
    $value  =  trim ( $value ); 
    return;
  }
  array_walk ( $value ,  'trim_value' );
}
array_walk ($Array,  'trim_value' );

Selenium处理验证码

发布时间:September 20, 2015 // 分类:PHP,iMacros // No Comments

截取整个屏幕,获取验证码坐标及大小,然后再截取验证码:

<?php
$element = $webDriver->findElement(
  WebDriverBy::id('J-checkcode-img')
);
$element_width = $element->getSize()->getWidth();
$element_height = $element->getSize()->getHeight();
 
$element_src_x = $element->getLocation()->getX();
$element_src_y = $element->getLocation()->getY();
 
$webDriver->takeScreenshot('screenshot.png');
$src = \imagecreatefrompng('screenshot.png');
$dest = \imagecreatetruecolor($element_width, $element_height);
 
imagecopy($dest, $src, 0, 0, $element_src_x, $element_src_y, $element_width, $element_height);
imagepng($dest, './captcha.png');

PHP多多线程pthreads数据共享

发布时间:June 19, 2015 // 分类:PHP // No Comments

<?php
class sharr extends Stackable {
  public function run(){}
}

class shvar extends Stackable  {
  public $num = 1;

}

class my extends Thread {

  public function __construct($sharr, $shvar) {
    $this->sharr = $sharr; 
    $this->shvar = $shvar; 
  }

  public function run(){
    $i = 0;
    while(++$i < 10) {
      $this->sharr[]=rand(0,1000);
      $this->shvar->num++;
    }
    var_dump($this->sharr);
    var_dump($this->shvar->num);
  } 
}

$sharr = new sharr();
$shvar = new shvar();
$my = new my($sharr, $shvar);
$my->start();
$my->join();

var_dump($sharr);
var_dump($shvar->num);
?>
分类
最新文章
最近回复
  • boscotsang: 请问下服务器端如何控制权限让通过权限认证的客户端才能连接?现在这样只要有自编译的客户端程序都可...
  • yck932: 大侠,请问哪里有 tunnels 详细参考资料,谢谢
  • bubble: 现在linux 4.9以上的内核有个bbr的参数,用这个bbr比用锐速效果更好,可参考我的博文...
  • wang: openwrt 只有 tmp/etc/miniupnpd.conf 修改后又重置了,其他路径找...
  • wbq: 可以了 只是https透明代理如何做呢?
  • wbq: 你的这个配置需要浏览器设置代理ip+port, 现在假设不设置,只配置客户端网关为Nginx那...
  • wbq: 您好,想用Nginx做个透明代理,客户端机器配置下网关(即Nginx那台机器),客户端dns配...
  • ccc: 可以提供易调用openssl常用函数吗?
  • 夜未央: 在centos7 下面 貌似转换不了。有人遇到过么????
  • brian: 博主你好,请教一个问题。我使用fprobe进行将交换机流量转换成netflow时是没有问题的,...