Recently in the development of the public number found a problem, that is PHP7.1 in the mcrypt has been discarded, then only to find a way to solve this problem, today to everyone about how I solve this problem and solve the idea.
The new features of php7.1 have attracted many phper, and everyone is discussing the benefits and conveniences of new features. But upgrading from php7.0 to php7.1 (obsolete) is an extension (mcrypt extension) that has been widely used in the past. The official provided the corresponding solution, but did not provide a more detailed solution. So the pit came:
Today, when connecting to a content management system using an open platform, it has failed to bind the public number.
Reason:
debugging, the direct reason is because the open platform filled with the authorization event (the authorization event every 10 minutes to send an event to update ticket), namely:
This place filled in the URL, debugging found that this URL is correct, there are every 10 minutes pushed to come over, but to the last direct receive ticket, see Code Discovery is because the decrypted data when the error:
<?php function Aes_decode ($message, $encodingaeskey = ', $appid = ') {$key = Base64_decode ($encodingaeskey. '='); $ciphertext _dec = Base64_decode ($message); $iv = substr ($key, 0, +); $module = Mcrypt_module_open (mcrypt_rijndael_128, ', MCRYPT_MODE_CBC, '); Mcrypt_generic_init ($module, $key, $IV); $decrypted = Mdecrypt_generic ($module, $ciphertext _dec); Mcrypt_generic_deinit ($module); Mcrypt_module_close ($module); $pad = Ord (substr ($decrypted,-1)); if ($pad < 1 | | $pad > +) {$pad = 0;}
This is the place, because my environment is PHP 7.1, find data found PHP 7.1 has abandoned mcrypt, so the code inside the mcrypt_* are not able to run.
Solve:
Find data discovery, you can replace MCrypt with OpenSSL (provided the OpenSSL extension is already installed, but is usually installed by default)
OpenSSL is a powerful toolkit that integrates a wide range of cryptographic algorithms and utilities. We can use the command desk tools it provides to generate keys, certificates to encrypt and decrypt files, or to encrypt the transmitted information in code using the API interfaces it provides.
So the above code can be changed to:
<?php function Aes_decode ($message, $encodingaeskey = ', $appid = ') {$key = Base64_decode ($encodingaeskey. '='); $ciphertext _dec = Base64_decode ($message); $iv = substr ($key, 0, +); /* MCrypt Symmetric decryption code has been discarded in PHP7.1, so use the following OpenSSL instead of $module = Mcrypt_module_open (mcrypt_rijndael_128, ", MCRYPT_MODE_CBC , ''); Mcrypt_generic_init ($module, $key, $IV); $decrypted = Mdecrypt_generic ($module, $ciphertext _dec); Mcrypt_generic_deinit ($module); Mcrypt_module_close ($module); */$decrypted = Openssl_decrypt ($ciphertext _dec, ' AES-256-CBC ', $key, openssl_raw_data| Openssl_zero_padding, $IV); $pad = Ord (substr ($decrypted,-1)); if ($pad < 1 | | $pad > +) {$pad = 0;}
Add:
The above decryption has been modified, then the corresponding MCrypt encryption needs to be modified, if not changed, will cause not to publish the whole network and can not push messages and other events
The encrypted source code is as follows:
<?phpfunction Aes_encode ($message, $encodingaeskey = ', $appid = ') {$key = Base64_decode ($encodingaeskey. '='); $text = Random (16). Pack ("N", strlen ($message)). $message. $appid; $iv = substr ($key, 0, +); $block _size = 32; $text _length = strlen ($text); $amount _to_pad = $block _size-($text _length% $block _size); if ($amount _to_pad = = 0) {$amount _to_pad = $block _size;} $pad _chr = Chr ($amount _to_pad); $tmp = "; for ($index = 0; $index < $amount _to_pad; $index + +) {$tmp. = $pad _chr;} $text = $text. $tmp; $size = Mcrypt_get_block_size (mcrypt_rijndael_128, MCRYPT_MODE_CBC); $module = Mcrypt_module_open (mcrypt_rijndael_128, ', MCRYPT_MODE_CBC, '); Mcrypt_generic_init ($module, $key, $IV); $encrypted = Mcrypt_generic ($module, $text); Mcrypt_generic_deinit ($module); Mcrypt_module_close ($module); $encrypt _msg = Base64_encode ($encrypted); return $encrypt _msg;}
The modified code is:
<?phpfunction Aes_encode ($message, $encodingaeskey = ', $appid = ') {$key = Base64_decode ($encodingaeskey. '='); $text = Random (16). Pack ("N", strlen ($message)). $message. $appid; $iv = substr ($key, 0, 16); $block _size = 32; $text _length = strlen ($text); $amount _to_pad = $block _size-($text _length% $block _size); if ($amount _to_pad = = 0) {$amount _to_pad = $block _size;} $pad _chr = Chr ($amount _to_pad); $tmp = "; for ($index = 0; $index < $amount _to_pad; $index + +) {$tmp. = $pad _chr;} $text = $text. $tmp; /* MCrypt symmetric encryption code in PHP7.1 has been discarded, so use the following OpenSSL instead of $size = Mcrypt_get_block_size (mcrypt_rijndael_128, MCRYPT_MODE_CBC); $module = Mcrypt_module_open (mcrypt_rijndael_128, ', MCRYPT_MODE_CBC, '); Mcrypt_generic_init ($module, $key, $IV); $encrypted = Mcrypt_generic ($module, $text); Mcrypt_generic_deinit ($module); Mcrypt_module_close ($module); */$encrypted = Openssl_encrypt ($text, ' AES-256-CBC ', $key, openssl_raw_data| Openssl_zero_padding, $IV); $encrypt _msg = base64_enCode ($encrypted); return $encrypt _msg;}
Special NOTE: All involved in the development process, if it has been upgraded to PHP 7.1, then it is necessary to check whether the use of mcrypt symmetric plus decryption, the development document used in the demo is also using MCrypt encryption, which needs to be noted.
Summarize
An example of Ajax asynchronous request technology
What is the common syntax for Ajax?
Ajax principle and the method of Cors cross-domain