Home >PHP Framework >YII >yii encrypted string garbled characters

yii encrypted string garbled characters

angryTom
angryTomOriginal
2020-02-17 11:15:331862browse

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);

$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!

Statement:
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