首页
开发手册
应用中心
工具
用户中心
FoundPHP Encryption Algorithm Research
English
中文简体
English
上一篇
下一篇
### FoundPHP Encryption Algorithm Research FoundPHP is a powerful framework that provides developers with encryption algorithms, including PHP's own built-in, which allows users to use it faster and more conveniently. #### 1. PHP Encryption/Decryption Library | Method | Usage | Description | | ------------ | ------------ | ------------ | | md5 | md5('foundphp'); | One-way encryption cannot be decrypted, and 32-bit characters are encrypted, mostly used for user password storage | | sha1 | sha1($password); | An irreversible encryption, similar to md5 encryption | | base64_encode | $str = base64_encode('foundphp'); | Standard base64 encryption algorithm, which can encrypt characters into a combination of characters and numbers, and can be decrypted, usually used for address bar data transmission or interface transmission | | base64_decode | $str = base64_decode($str); | Decrypt the standard base64 encoding and become a string after decryption. | | urlencode | urlencode('http://www.foundphp.com') | The string is encoded and used in the request part of the URL, and it is also convenient to pass variables to the next page | | urldecode | urlencode('http%3A%2F%2Fwww.xxx.com') | Decode any %## in the encoded string. The plus sign ('+') is decoded into a space character. |
#### 2. FoundPHP Encryption/Decryption Library FoundPHP provides an encryption library, which uses ASE and DES methods respectively, and the code needs to be configured in data/config.php ``` $config['encrypt']['type'] ='AES'; //AES and DES $config['encrypt']['key'] = '66054b8866054b8866054b8866054b88'; //Docking key, AES is 32 bits (16-bit length characters are used for java docking), DES is 8 bits $config['encrypt']['iv'] ='www.FoundPHP.comwww.FoundPHP.com'; //Encryption offset value AES is 32 bits (16-bit length characters used for docking with java), DES is 8 bits ``` | Method | Usage | Description | | ------------ | ------------ | ------------ | | encode | $str = $GLOBALS['FoundPHP_encrypt']->encode('foundphp'); | Encryption method that can be decrypted using key encoding method | | decode | $GLOBALS['FoundPHP_encrypt']->decode($password); | Decryption method of corresponding key | **Usage:** plugin/model/default.php ``` //coding $str = $GLOBALS['FoundPHP_encrypt']->encode('test code'); echo 'encryption:'.$str.'
'; echo 'decrypt:'.$GLOBALS['FoundPHP_encrypt']->decode($str); ``` Output result: ``` encryption:gQA3/rvsJ9afv1+qXuM0/A== decrypt:test code ``` This method is mostly used to encrypt when user information needs to be transmitted across websites or projects to prevent it from being decoded by others. As long as the key of the project is changed, the old encryption string cannot be used, so the two projects can be connected as long as the key is the same. data. For the transmission of complex data, we can compile the array or object into json, then encrypt the json data, and transfer the encrypted data to another project. After the project is decrypted, the json can be used to call the data.