可以使用git reflog show –date=iso remotes/origin/xxx 这个命令来追溯
PHP5.6.40进行RSA加解密
最近因为工作编写接口安全用到RSA加密解密,记录下。
环境:windows10,php5.6.40
下载OpenSSL安装地址:http://slproweb.com/products/Win32OpenSSL.html
安装后cmd进入bin目录进行生成私钥和公钥
//生成私钥
openssl genrsa -out rsa_private_key.pem 1024
//生成公钥
openssl rsa -in rsa_private_key.pem -pubout -out rsa_public_key.pem
将生成的私钥、公钥拷贝到你的php执行目录中。
用下面价格函数就可以实现rsa加解密了
openssl_pkey_get_private openssl_private_decrypt openssl_private_encrypt openssl_pkey_get_public openssl_public_decrypt openssl_public_encrypt
参考资料:https://www.php.net/manual/zh/book.openssl.php
./swoole_config.h:22:2: error: #error “GCC 4.8 or later required”
Centos下php7安装swoole 扩展的时候,提示的错误。我记得gcc 版本升级过一次到4.8.5,无语。
root@netpc.com.cn swoole-4.3.5]# gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/i686-pc-linux-gnu/4.8.5/lto-wrapper
Target: i686-pc-linux-gnu
Configured with: ../configure -enable-checking=release -enable-languages=c,c++ -disable-multilib
Thread model: posix
gcc version 4.8.5 (GCC)
[root@netpc.com.cn swoole-4.3.5]# cc -v
Using built-in specs.
Target: i386-redhat-linux
Configured with: ../configure –prefix=/usr –mandir=/usr/share/man –infodir=/usr/share/info –enable-shared –enable-threads=posix –enable-checking=release –with-system-zlib –enable-__cxa_atexit –disable-libunwind-exceptions –enable-libgcj-multifile –enable-languages=c,c++,objc,obj-c++,java,fortran,ada –enable-java-awt=gtk –disable-dssi –disable-plugin –with-java-home=/usr/lib/jvm/java-1.4.2-gcj-1.4.2.0/jre –with-cpu=generic –host=i386-redhat-linux
Thread model: posix
gcc version 4.1.2 20080704 (Red Hat 4.1.2-55)
老旧共存啊?!
先找下到底有多少gcc
[root@netpc.com.cn ~]# find / -name ‘gcc’
/usr/bin/gcc
/usr/libexec/gcc
/usr/lib/gcc
/usr/local/bin/gcc
/usr/local/libexec/gcc
/usr/local/lib/gcc
/usr/local/src/gcc-4.8.5/gcc-build-4.8.5/gcc
/usr/local/src/gcc-4.8.5/gcc
/usr/local/src/gcc-4.8.5/gcc/testsuite/ada/acats/tests/gc
接着替换下:
mv /usr/bin/gcc /usr/bin/gcc4.1.2
ln -s /usr/local/bin/gcc /usr/bin/gcc
搞定
centos升级autoconf
服务器Centos因为安装一些包发现autoconf版本不够,需要升级。
[root@netpc.com.cn ]# rpm -qf /usr/bin/autoconf
autoconf-2.59-12
[root@netpc.com.cn ]# rpm -e –nodeps autoconf-2.59-12
[root@netpc.com.cn ]# wget ftp://ftp.gnu.org/gnu/autoconf/autoconf-2.69.tar.gz
[root@netpc.com.cn src]# tar zxvf ./autoconf-2.69.tar.gz
[root@netpc.com.cn src]# cd autoconf-2.69
[root@netpc.com.cn autoconf-2.69]# ./configure –prefix=/usr/
make&&make install
[root@netpc.com.cn autoconf-2.69]# /usr/bin/autoconf -V
autoconf (GNU Autoconf) 2.69
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+/Autoconf: GNU GPL version 3 or later
<http://gnu.org/licenses/gpl.html>, <http://gnu.org/licenses/exceptions.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Written by David J. MacKenzie and Akim Demaille.
搞定
【原创】php7安装扩展错误AS_CASE、AC_DEFINE、AC_CANONICAL_HOST
今天服务器安装swoole扩展死活提示错误:
[root@netpc.com.cn swoole-4.0.0]# /usr/local/php7/bin/phpize
Configuring for:
PHP Api Version: 20151012
Zend Module Api No: 20151012
Zend Extension Api No: 320151012
config.m4:262: warning: AC_CANONICAL_HOST invoked multiple times
configure:7794: error: possibly undefined macro: AS_CASE
If this token and others are legitimate, please use m4_pattern_allow.
See the Autoconf documentation.
configure:7801: error: possibly undefined macro: AC_DEFINE
查README和文档里
autoconf 2.69
gcc 4.8
查询本机发现autoconf版本低了
[root@netpc.com.cn swoole-4.0.0]# rpm -qf /usr/bin/autoconf
autoconf-2.59-12
升级后搞定。
【原创】PHP补充API接口数据安全验证加密解密相关问题
用PHP写了这么久api接口,需要总结下关于限制的一些问题。
通常接口有对外或对内情况,下面说下相关能用上的规则:
- 限制IP、访问频率等,根据什么来判断就看你了。
- 用户名和密码登陆,验证成功后,生成token,可以有过期限制。
- sign作用:传过来的数据,根据规则生成sign,与传过来的sign对比。也是相当于验证身份
- https保护保存数据
以上还不能保证数据安全,有可能你通过接口身份验证后传输数据还是有可能被路由、终端等拦截数据。
这时候可以选择数据加密方式,以下几种常用的:
DES:Data Encrytion Standard(数据加密标准),对应算法是DEA
特点:1. 对称加密 2. 同一个SK(跨平台可能会。。。)
AES:Advanced Encrytion Standard(高级加密标准)
特点:1. 对称加密 2. 一个SK扩展成多个子SK,轮加密(速度快)
RSA:特点: 1. 非对称加密,即:PK与SK不是同一个
2. PK用于加密,SK用于解密
3. PK决定SK,但是PK很难算出SK(数学原理:两个大质数相乘,积很难因式分解)
4. 速度慢,只对少量数据加密
介绍完特别后你知道选择什么了吧?
PHP 的 OpenSSL 扩展中加密的相关函数有:
- openssl_encrypt()
- openssl_decrypt()
详细看官方手册:https://www.php.net/manual/zh/function.openssl-encrypt.php
也有直接对外暴露在web上的随便访问毫无限制的对外接口,那???
【原创】PHP循环非递归或递归实现斐波那契数列Fibonacci
//参数按第几位算,零是第一位,第九位21。
//0, 1, 1, 2, 3, 5, 8, 13,21
//For非递归方式
echo Fibonacci_netpc(9);
echo Fibonacci_R(9);
function Fibonacci_netpc($n)
{
if ($n > 2) {
$o = 0;
$t = 1;
for ($i = 4; $i <= $n; $i++) {
//调换保存最后2位累加位置
$temp = $o + $t;
$o = $t;
$t = $temp;
}
return $t + $o;
} else {
return $n - 1;
}
}
//递归方式
function Fibonacci_R($n)
{
if ($n < 3) return $n - 1;
if ($n == 3) return 1;
return Fibonacci_R($n - 1) + Fibonacci_R($n - 2);
}
[原创]svn 删除更新某条历史记录
这个问题?答案是有可能的。
如果是刚刚发生的记录,处理起来就相对容易,如果你提交到2001次记录刚好发现是不想要。
首先导出svn版本库记录
svnadmin dump netpc.com.cn -r 0:1000 > netpc.dump
svnadmin dump netpc.com.cn -r 1001:2000 –incremental > netpc-1001-2000.dump
incremental增量方式是考虑到如果需要修改某部分记录,而整个版本库又太大,你只能分段导出成小文件,便于修改。
修改原库netpc.com.cn名字为netpc.com.cn.old
创建个新的:svnadmin create /data/svn/netpc.com.cn
导入:
svnadmin load netpc.com.cn < netpc.dump
svnadmin load netpc.com.cn < netpc-1001-2000.dump
重新提交记录就可以了。
本地或远程其它地方拉取svn库更新源码的时候有可能会提示:出现校验和不匹配问题
那就进入对应的目录,不需要全库更新,然后清空再拉取即可。
svn update –set-depth empty
svn update –set-depth infinity
如果要更新历史上某段记录,打开dump文件看看应该就明白,涉及到源码变化关联md5,这部分处理起来就麻烦的多,根据需求自己试试看。
【原创】微信小程序api接口https要求TLS大于等于1.2
VM8 asdebug.js:1 https://netpc.com.cn 对应的服务器 TLS 为 TLS 1.0 ,小程序要求的 TLS 版本必须大于等于 1.2 。控制台输入 showRequestInfo() 可以获取更详细信息。
搜索发现TLS1.2至少openssl需要1.0.2版本,上服务器一看发现版本低了。
[root@netpc.com.cn nginx-1.10.2]# nginx -V
nginx version: nginx/1.10.2
built by gcc 4.1.2 20080704 (Red Hat 4.1.2-54)
built with OpenSSL 0.9.8e-fips-rhel5 01 Jul 2008
[root@netpc.com.cn ~]# openssl version -a
升级更新openssl
wget https://www.openssl.org/source/openssl-1.0.2q.tar.gz
tar zxvf openssl-1.0.2q.tar.gz
cd openssl-1.0.2q
./config
make
make install
安装后发现版本没变,执行下面的代码更新
/usr/local/ssl/bin/openssl -version
/usr/local/ssl/bin/openssl version
mv /usr/bin/openssl /usr/bin/openssl.bak
mv /usr/include/openssl /usr/include/openssl.bak
ln -s /usr/local/ssl/bin/openssl /usr/bin/openssl
ln -s /usr/local/ssl/include/openssl /usr/include/openssl
echo “/usr/local/ssl/lib” >> /etc/ld.so.conf
ldconfig -v
这样就发现变过来了,可是还是不行,执行nginx -V查看还是0.9.8e,看来需要重新编译下nginx,编译新的源码是如果出错,可以指定–with-openssl这个参数到新的版本源码目录上。
./configure –user=www –group=www –prefix=/usr/local/nginx –with-http_stub_status_module –with-http_ssl_module –with-http_gzip_static_module –with-ipv6 –add-module=/usr/local/src/nginx-http-concat/ –add-module=/usr/local/src/ngx_cache_purge-2.3 –with-openssl=/usr/local/src/openssl-1.0.2q
最后安装成功,再查看下版本上去了。
[root@netpc.com.cn ~]# nginx -V
nginx version: nginx/1.18.0
built by gcc 4.1.2 20080704 (Red Hat 4.1.2-55)
built with OpenSSL 1.0.2q 20 Nov 2018
可以用以下命令检测是否支持
openssl s_client -connect www.netpc.com.cn:443 -tls1
openssl s_client -connect www.netpc.com.cn:443 -tls1_1
openssl s_client -connect www.netpc.com.cn:443 -tls1_2
找个网站检测下也可以,符合ATS就支持TLS1.2
【原创】微信小程序wx.getUserInfo获取加密encryptedData解密方法
刚开始找确实也不好找,就算在小程序官方文档里面也不好搜索:
在下面链接找到以下内容位置,有个点击下载,压缩包里面就有php,python,node,c++解密例子。
加密数据解密算法
接口如果涉及敏感数据(如wx.getUserInfo当中的 openId 和 unionId),接口的明文内容将不包含这些敏感数据。开发者如需要获取敏感数据,需要对接口返回的加密数据(encryptedData) 进行对称解密。 解密算法如下:
- 对称解密使用的算法为 AES-128-CBC,数据采用PKCS#7填充。
- 对称解密的目标密文为 Base64_Decode(encryptedData)。
- 对称解密秘钥 aeskey = Base64_Decode(session_key), aeskey 是16字节。
- 对称解密算法初始向量 为Base64_Decode(iv),其中iv由数据接口返回。
微信官方提供了多种编程语言的示例代码((点击下载)。每种语言类型的接口名字均一致。调用方式可以参照示例。
另外,为了应用能校验数据的有效性,会在敏感数据加上数据水印( watermark )
官方文档链接地址:https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/signature.html


