Home > PHP Framework > YII > body text

yii encrypted string garbled characters

angryTom
Release: 2020-02-17 11:15:33
Original
1694 people have browsed it

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 characters

yii encrypted string garbled code

First, encrypt the data

$encryptedData = Yii::$app->getSecurity()->encryptByPassword($data, $secretKey);
Copy after login

$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);
Copy after login

$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
Copy after login
//加密(此处加密密码设为空)
$uid = base64_encode(\yii::$app->security->encryptByPassword($id,''));
Copy after login
//解密
$iss=\yii::$app->security->decryptByPassword(base64_decode($uid),'');
Copy after login

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!

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!