For project requirements, we need to connect to an insurance company to call APIs. our company is the PHP backend and the insurance company is the java backend. data transmission in the middle cannot be prevented from being encrypted or decrypted, currently, we recommend that you use encrypted AES. For project requirements, we need to connect to an insurance company to call APIs. our company is the PHP backend and the insurance company is the java backend. data transmission in the middle cannot be prevented from being encrypted or decrypted, currently, we recommend that you use encrypted AES.
During the connection process, it is inevitable that the mountains will be migrated to the water,
The following describes the encryption instructions for my company:
Be sure to know your own encryption methods repeatedly. Otherwise, the results of a different encryption mode, ECB and CBC, will be very different.
The final code that can be used is attached:
'; // Echo Security: decrypt ($ value, $ key );
Call in common functions:
/*** Request body encryption ** @ param array $ information of the content applicant * @ return string */function hetai_encrypt ($ content) {// solution 7 print_r ("\ r \ n"); vendor ('encrypt. security ') or die ("solution 7 failed to be introduced"); $ sec = new \ Security (); $ string = $ content; $ sec_res = $ sec-> encrypt ($ string, base64_decode ("eeSvvVtUDLi5lTBHDjCeFw ="); $ sec_res = strToHex ($ sec_res ); // The result is converted to hexadecimal and converted to uppercase. // The conversion is performed several times here. // It is only to cater to the results I need. // Set it according to your own encryption requirements. $ encrypt_upper = strToHex (base64_decode (hexToStr ($ sec_res ))); var_dump ("\ r \ n solution 7 encryption result \ r \ n ". $ encrypt_upper); // decrypt $ sec_res_lower = strtolower ($ sec_res); // Convert it to lower case $ sec_res_lower_tostr = hexToStr ($ sec_res ); // Convert the hexadecimal string $ sec_dec = $ sec-> decrypt ($ sec_res_lower_tostr, base64_decode ("eeSvvVtUDLi5lTBHDjCeFw = ")); var_dump ("\ r \ n solution 7 decryption result \ r \ n ". $ sec_dec); return $ encrypt_upper ;}
Convert a binary string to a hexadecimal string or a hexadecimal string to a binary string:
/*** Convert string to hexadecimal format * @ param string $ string * @ return string */function strToHex ($ string) {$ hex = ""; for ($ I = 0; $ I
I have attached a three-day encrypted feature block that will only be used as a reminder ~
The above is the sample code (figure) for PHP to connect to the java AES/ECB/PKCS5Padding encryption method. For more information, see other related articles in the first PHP community!