下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、/index.php?php/需要配置PHP.INI文件,打开extension=php_openssl.dllincludersaclass.php;/以下是一个简单的测试demo,如果不需要请删除$rsa=newRsa(D:rsa);/放项目的PHP目录/私钥加密,公钥解密echosource:Testing:HelloWorld!;$pre=$rsa-privEncrypt(Testing:HelloWorld!);echoPrivateEncrypted:.$pre.;$pud=$rsa-pubDecrypt($pre);echoPublicDecrypted:.$pud.;/公钥加密
2、,私钥解密echosource:workinginhere!;$pue=$rsa-pubEncrypt(workinginhere!);echoPublicEncrypt:.$pue.;$prd=$rsa-privDecrypt($pue);echoPrivateDecrypt:.$prd;?/rsaclass.php_keyPath=$path;*createthekeypair,savethekeyto$this-_keyPath*/publicfunctioncreateKey()$r=openssl_pkey_new();openssl_pkey_export($r,$privKey)
3、;file_put_contents($this-_keyPath.DIRECTORY_SEPARATOR.key.pem,$privKey);$this-_privKey=openssl_pkey_get_public($privKey);$rp=openssl_pkey_get_details($r);$pubKey=$rpkey;file_put_contents($this-_keyPath.DIRECTORY_SEPARATOR.pub.pem,$pubKey);$this-_pubKey=openssl_pkey_get_public($pubKey);/*setupthepriv
4、atekey*/publicfunctionsetupPrivKey()if(is_resource($this-_privKey)returntrue;$file=$this-_keyPath.DIRECTORY_SEPARATOR.key.pem;$prk=file_get_contents($file);$this-_privKey=openssl_pkey_get_private($prk);returntrue;/*setupthepublickey*/publicfunctionsetupPubKey()if(is_resource($this-_pubKey)returntrue
5、;$file=$this-_keyPath.DIRECTORY_SEPARATOR.pub.pem;$puk=file_get_contents($file);$this-_pubKey=openssl_pkey_get_public($puk);returntrue;*encryptwiththeprivatekey*/publicfunctionprivEncrypt($data)if(!is_string($data)returnnull;$this-setupPrivKey();$r=openssl_private_encrypt($data,$encrypted,$this-_pri
6、vKey);if($r)returnbase64_encode($encrypted);returnnull;/*decryptwiththeprivatekey*/publicfunctionprivDecrypt($encrypted)if(!is_string($encrypted)returnnull;$this-setupPrivKey();$encrypted=base64_decode($encrypted);$r=openssl_private_decrypt($encrypted,$decrypted,$this-_privKey);if($r)return$decrypte
7、d;returnnull;/*encryptwithpublickey*/publicfunctionpubEncrypt($data)if(!is_string($data)returnnull;$this-setupPubKey();$r=openssl_public_encrypt($data,$encrypted,$this-_pubKey);if($r)returnbase64_encode($encrypted);returnnull;/*decryptwiththepublickey*/publicfunctionpubDecrypt($crypted)if(!is_string
8、($crypted)returnnull;$this-setupPubKey();$crypted=base64_decode($crypted);$r=openssl_public_decrypt($crypted,$decrypted,$this-_pubKey);if($r)return$decrypted;returnnull;publicfunction_destruct()fclose($this-_privKey);fclose($this-_pubKey);?加密使用公钥,解密使用私钥签名使用私钥,验证使用公钥私钥可以导出公钥I产牛私钥I,指定位数1024,公钥指数e,通常是3,17,65537$opensslg
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- T/CEPCA 1003-2024电力建设企业自律行为规范
- T/ZHHX 009-2025花境营建技术规程
- T/SAMD 0001-2023家用强脉冲光治疗仪
- T/UNP 95-2024长陔火腿加工工艺规范
- T/CPIA 0080-2024光伏组件用镀锌铝镁钢制边框
- 2026年摄像设计师摄像技术试题及答案
- T/TMAC 261.2-2025智能配电网 一二次融合柱上断路器 第2部分:动稳定性能试验方法
- T/HNNMIA 37-2023铝用炭素焙烧焦油资源化利用规范
- 2026年锅炉安全操作巡检考试试卷试题及答案
- 2026年化工企业中毒窒息处置考试试卷试题及答案
- 办公设备租赁合同协议(2025年扫描仪)
- 信息系统监理实施细则标准版范本
- 国企设备使用管理规程
- 大衣品类课件
- 时空耦合分类模型构建-洞察及研究
- GB/T 45472-2025架空和综合管廊用预制保温管道
- 急救与生命支持类设备管理
- 2025年湖北恩施州巴东县机关事业单位选调46人历年高频重点提升(共500题)附带答案详解
- 培训劳动纪律
- 如何做好临床护理带教组长
- 人教版六年级数学上册【全册教案】
评论
0/150
提交评论