今天偶然发现jsencrypt这玩意,之前做"直播室聊天"时 数据传输明文问题没解决; 一直苦苦寻找技术解决方案今天勉强找了个;
原理:javascript加密PHP解密; 完全依赖openssl; 一. openssl 是干嘛的
它集成了众多密码算法及实用工具 rsa加密流程;(今天只讲众多加密方式中的一种)
. 在当前文件夹下生成一个包含 "公钥"和"私钥" 两部分内容的文本文件; 命名test.key
[root@iZ28pw7sv4qZ openssl]#openssl genrsa -out test.key .将这个文本文件中的“公钥”提取出来: 命名test_pub.key
[root@iZ28pw7sv4qZ openssl]#openssl rsa -in test.key -pubout -out test_pub.key .创建一个hello.txt的文本文件,然后利用此前生成的公钥加密文件;
[root@iZ28pw7sv4qZ openssl]#echo "" > ./hello.txt
[root@iZ28pw7sv4qZ openssl]#openssl rsautl -encrypt -in hello.txt -inkey test_pub.key -pubin -out hello.en.txt .解密文件
[root@iZ28pw7sv4qZ openssl]#openssl rsautl -decrypt -in hello.en.txt -inkey test.key -out hello.de.txt .解析后的结果
[root@iZ28pw7sv4qZ openssl]# cat hello.de.txt 二. jsencrypt.js这个文件定义了一个JSEncrypt方法 可以去git搜一下 对于此篇文档就不展开太多
使用步骤
var res = new JSEncrypt
res.setPublicKey('---这里就填写test_pub.key文件中的字符串内容---'); //设置公有key
var temp = res.encrypt("123456789罗源县中华失联飞机安抚拉斯加 大是的发生两地");//利用刚设好的key 对明文进行加密;
var data = encodeURI(temp).replace(/\+/g, '%2B'), //+号的处理: 加密完成后就可以ajax传送了

下载地址: http://files.cnblogs.com/files/sixiong/openssl.zip

最新文章

  1. airline 設定 安裝
  2. 在ie与火狐的兼容性
  3. WPF控件 RichTextBox查找定位匹配字符
  4. 剑指Offer:面试题33——把数组排成最小的数(java实现)(未完待续)
  5. linux下c程序的链接、装载和库(1)
  6. jQuery上定义插件并重设插件构造函数
  7. Little Jumper---(三分)
  8. angular 倒计时
  9. 【Shell脚本学习17】Shell case esac语句
  10. sharepoint中的YesNo字段
  11. php设计模式之单例模式
  12. Silverlight代码编写对控件的PlaneProjection.RotationY属性控制动画
  13. html bottom html submit按钮表单控件与CSS美化
  14. 微信内置浏览器私有接口WinXinJsBridge介绍
  15. 末学者笔记——SAMBA服务、FTP服务讲解
  16. 跟随我在oracle学习php(7)
  17. 工欲善其事,必先利其器-ecplise配置和优化
  18. Linux卸载搭建环境
  19. multiple definition of 问题解决方法
  20. (LeetCode74)Search a 2D Matrix

热门文章

  1. 关于nginx报错/usr/share/nginx/html/jiankongshare" failed (2: No such file or directory)的问题解决
  2. Android通讯:通话
  3. selenium和pyquery抓取异步加载数据
  4. vue-cli 搭建的项目处理不同环境下请求不同域名的问题
  5. Application.ProcessMessages; 的重要性
  6. python爬取百度贴吧帖子
  7. 【Java】 剑指offer(59-2) 队列的最大值
  8. 利用IntelliJ IDEA 创建第一个项目
  9. Linux —— 常见指令及其英文全称
  10. 使用cxf两个声明导致ObjectFactory 类中发生冲突