


我也是PHP新手,通过w3cschool了解了一下php基本原理之后就开写了。但仍是菜鸟。
先不管3DES加密的方法对不对,方法都是网上的,在运行的时候报了个错,把小弟整死了。找来找去终于自己摸出了方法。
<?php /** * * PHP版3DES加解密类 * * 可与java的3DES(DESede)加密方式兼容 * * @Author: Luo Hui (farmer.luo at gmail.com) * * @version: V0.1 2008.12.04 * */ class Crypt3Des { public $key = "01234567890123456789012345678912"; public $iv = "23456789"; //like java: private static byte[] myIV = { 50, 51, 52, 53, 54, 55, 56, 57 }; //加密 public function encrypt($input) { $input = $this->padding( $input ); $key = base64_decode($this->key); $td = mcrypt_module_open( MCRYPT_3DES, '', MCRYPT_MODE_CBC, ''); //使用MCRYPT_3DES算法,cbc模式 mcrypt_generic_init($td, $key, $this->iv); //初始处理 $data = mcrypt_generic($td, $input); //加密 mcrypt_generic_deinit($td); //结束 mcrypt_module_close($td); $data = $this->removeBR(base64_encode($data)); return $data; } //解密 public function decrypt($encrypted) { $encrypted = base64_decode($encrypted); $key = base64_decode($this->key); $td = mcrypt_module_open( MCRYPT_3DES,'',MCRYPT_MODE_CBC,''); //使用MCRYPT_3DES算法,cbc模式 mcrypt_generic_init($td, $key, $this->iv); //初始处理 $decrypted = mdecrypt_generic($td, $encrypted); //解密 mcrypt_generic_deinit($td); //结束 mcrypt_module_close($td); $decrypted = $this->removePadding($decrypted); return $decrypted; } //填充密码,填充至8的倍数 public function padding( $str ) { $len = 8 - strlen( $str ) % 8; for ( $i = 0; $i < $len; $i++ ) { $str .= chr( 0 ); } return $str ; } //删除填充符 public function removePadding( $str ) { $len = strlen( $str ); $newstr = ""; $str = str_split($str); for ($i = 0; $i < $len; $i++ ) { if ($str[$i] != chr( 0 )) { $newstr .= $str[$i]; } } return $newstr; } //删除回车和换行 public function removeBR( $str ) { $len = strlen( $str ); $newstr = ""; $str = str_split($str); for ($i = 0; $i < $len; $i++ ) { if ($str[$i] != '\n' and $str[$i] != '\r') { $newstr .= $str[$i]; } } return $newstr; } } //test $input = "1qaz2ws"; echo "plainText:" . $input."<br/>"; $crypt = new Crypt3Des(); echo "Encode:".$crypt->encrypt($input)."<br/>"; echo "Decode:".$crypt->decrypt($crypt->encrypt($input)); ?>
代码可以不看,就看里面的一句:$td = mcrypt_module_open( MCRYPT_3DES, '', MCRYPT_MODE_CBC, '');报错的就是他。
我搜寻了一大堆解决方法,正确的方法应该是(仅用于windows系统哦):
当运行php的服务器端缺少libmcrypt.dll时使用函数mcrypt_module_open进行解密会出现此错误。
在服务器上做如下设置可解决。
到网上下载一个php的mcrypt模块安装包,只需要libmcrypt.dll文件即可(一般官网上下载的,php目录下已经有的)
1.将libmcrypt.dll复制到system32目录或php安装目录下的extensions目录下
2.将libmcrypt.dll复制到apache安装目录的bin目录下
3.到windows目录下找到php.ini文件,打开它
4.找到; Directory in which the loadable extensions (modules) reside.
extension_dir = "./" 如:extension_dir = "D:\php5\ext"
这两行,要使extension_dir指向的目录下能找到libmcrypt.dll,或系统path下有libmcrypt.dll
5.找到;Windows Extensions 项下面的;extension=php_mcrypt.dll这一行和;extension=php_iconv.dll(我的没有,省略了)这两行,去掉前面的分号
ps:刚开始看网上的解决方法,有的说修改php安装目录下的php.ini,但是修改后是没用的。一定要修改windows目录下的php.ini!

ThesecrettokeepingaPHP-poweredwebsiterunningsmoothlyunderheavyloadinvolvesseveralkeystrategies:1)ImplementopcodecachingwithOPcachetoreducescriptexecutiontime,2)UsedatabasequerycachingwithRedistolessendatabaseload,3)LeverageCDNslikeCloudflareforservin

You should care about DependencyInjection(DI) because it makes your code clearer and easier to maintain. 1) DI makes it more modular by decoupling classes, 2) improves the convenience of testing and code flexibility, 3) Use DI containers to manage complex dependencies, but pay attention to performance impact and circular dependencies, 4) The best practice is to rely on abstract interfaces to achieve loose coupling.

Yes,optimizingaPHPapplicationispossibleandessential.1)ImplementcachingusingAPCutoreducedatabaseload.2)Optimizedatabaseswithindexing,efficientqueries,andconnectionpooling.3)Enhancecodewithbuilt-infunctions,avoidingglobalvariables,andusingopcodecaching

ThekeystrategiestosignificantlyboostPHPapplicationperformanceare:1)UseopcodecachinglikeOPcachetoreduceexecutiontime,2)Optimizedatabaseinteractionswithpreparedstatementsandproperindexing,3)ConfigurewebserverslikeNginxwithPHP-FPMforbetterperformance,4)

APHPDependencyInjectionContainerisatoolthatmanagesclassdependencies,enhancingcodemodularity,testability,andmaintainability.Itactsasacentralhubforcreatingandinjectingdependencies,thusreducingtightcouplingandeasingunittesting.

Select DependencyInjection (DI) for large applications, ServiceLocator is suitable for small projects or prototypes. 1) DI improves the testability and modularity of the code through constructor injection. 2) ServiceLocator obtains services through center registration, which is convenient but may lead to an increase in code coupling.

PHPapplicationscanbeoptimizedforspeedandefficiencyby:1)enablingopcacheinphp.ini,2)usingpreparedstatementswithPDOfordatabasequeries,3)replacingloopswitharray_filterandarray_mapfordataprocessing,4)configuringNginxasareverseproxy,5)implementingcachingwi

PHPemailvalidationinvolvesthreesteps:1)Formatvalidationusingregularexpressionstochecktheemailformat;2)DNSvalidationtoensurethedomainhasavalidMXrecord;3)SMTPvalidation,themostthoroughmethod,whichchecksifthemailboxexistsbyconnectingtotheSMTPserver.Impl


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Linux new version
SublimeText3 Linux latest version

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Notepad++7.3.1
Easy-to-use and free code editor
