Home > Article > Backend Development > Tutorial on the use of several methods of php encryption and decryption
In daily project development, it is often necessary to use PHP to encrypt specific information, that is, an encrypted string is generated through the encryption algorithm. This encrypted string can be decrypted through the decryption algorithm, which facilitates the program to process the decrypted information. deal with.
So in this course we will introduce you to the detailed explanation of the use of PHP encryption and decryption classes. Then we first download the PHP encryption and decryption classes we need this time: http://www.php. cn/xiazai/leiku/829
After we download the class, put the file in the local editor, and then instantiate the class:
<?php //实例化类 $obj = new crypt('1111'); //定义数值 $value = "111111"; $string = 123456; //输出 echo $obj->decode($value) ."<br>"; echo $obj->encode($value)."<br>"; echo $obj->safe_b64encode($string)."<br>"; echo $obj->safe_b64decode($string)."<br>";
The running results are as follows:
Explanation:
Here we have garbled characters after encryption and decryption. This is a problem with our encoding format, so we need to add a piece of code to the file header, which is to modify the encoding format:
header("Content-type:text/html;charset=utf-8");
in the file header After adding this code, there will be no garbled characters! I won’t post pictures here, you can try it yourself~
The above is the detailed content of Tutorial on the use of several methods of php encryption and decryption. For more information, please follow other related articles on the PHP Chinese website!