Monday, April 30, 2018

yii2 encrypt decrypt

Yii2 encrypt decrypt data

Yii2 have inbuilt functions for encrypt/decrypt data using secret key. You need secret key to decrypt the data. So if the person have secret key he/she will be decrypt the data easily using the getSecurity() method. Below example is showing the data encrypt/decrypt:

$data = 'FORM DATA';
$secretKey = 'YOUR SECRET KEY'
$encryptData = Yii::$app->getSecurity()->encryptByPassword($data, $secretKey);

$data = Yii::$app->getSecurity()->decryptByPassword($encryptData, $secretKey);

1 comment: