Home >PHP Framework >YII >yii encrypted string garbled characters
Yii provides convenient helper functions that allow you to encrypt and decrypt data using a security key. Data is transmitted through an encryption function so that only someone with the security key can decrypt it.
yii encrypted string garbled code
First, encrypt the data
$encryptedData = Yii::$app->getSecurity()->encryptByPassword($data, $secretKey);
$data is you The content to be encrypted,
$secretKey is the password you set yourself,
Later, when the user needs to read the data:
Recommended related article tutorials: yiiTutorial
$data = Yii::$app->getSecurity()->decryptByPassword($encryptedData, $secretKey);
$encryptedData is the content you want to decrypt
$secretKey is the password you set when encrypting
But when the string is encrypted, the encrypted string looks like a string of garbled characters.
Solution:
We can use base64 to process the encrypted string. The processed string is composed of letters and numbers
Application examples:
//邀请注册 $id = Yii::$app->user->getId();//获取登录用户id
//加密(此处加密密码设为空) $uid = base64_encode(\yii::$app->security->encryptByPassword($id,''));
//解密 $iss=\yii::$app->security->decryptByPassword(base64_decode($uid),'');
Please visit Programming Tutorial to get more YII related development knowledge!
The above is the detailed content of yii encrypted string garbled characters. For more information, please follow other related articles on the PHP Chinese website!