Home > Backend Development > PHP Problem > How to solve the php encryption garbled problem

How to solve the php encryption garbled problem

藏色散人
Release: 2023-03-07 18:08:01
Original
3962 people have browsed it

The solution to php encryption garbled characters: first encrypt the ciphertext with MD5; then use base64 encryption to avoid garbled characters. The code statement is "$bs_test = base64_encode($test);".

How to solve the php encryption garbled problem

# Recommended: "

PHP Video Tutorial

The operating environment of this tutorial: Windows 7 system, PHP version 5.6. This method is suitable for all brands of computers.

In a recent project, the original functions were encapsulated into an interface for third-party calls. Among them, signature encryption was involved. RES encryption was used. The idea was to use public keys and The POST parameters are spliced ​​into a string and then public key encrypted. However, RES encryption has requirements for ciphertext and has a length limit. If the POST data is too long, the ciphertext data will be too long and the decryption will fail. Therefore, our idea to solve this problem is to encrypt the ciphertext with MD5 and then encrypt the encrypted data with RES. However, the RES-encrypted data may also be encrypted due to Encoding problems lead to garbled characters, so we also need to perform base64 encryption to avoid garbled characters.

The simple code is shown below:

/*
*$rsa_pub为RES公钥
*
*/$secret = md5($querystr . $api_secret); 
//组成密文
openssl_public_encrypt($secret ,$test, $rsa_pub); //公钥加密  
$bs_test = base64_encode($test);  //进行base64加密
Copy after login

The above is the detailed content of How to solve the php encryption garbled problem. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template