Use libsodium to encrypt all data, related to OAuth2

This commit is contained in:
ErickSkrauch
2019-12-06 14:37:51 +03:00
parent 642db2e045
commit 6fb32ec76d
10 changed files with 71 additions and 19 deletions

View File

@ -0,0 +1,26 @@
<?php
declare(strict_types=1);
namespace api\components\OAuth2;
use Yii;
/**
* This trait is intended to override the standard data encryption behavior
* with the help of \Defuse\Crypto\Crypto class, because the resultant string
* is much larger than the original one.
*
* The implementation under the hood relies on using libsodium library
* that provides more compact result values.
*/
trait CryptTrait {
protected function encrypt($unencryptedData): string {
return Yii::$app->tokens->encryptValue($unencryptedData);
}
protected function decrypt($encryptedData): string {
return Yii::$app->tokens->decryptValue($encryptedData);
}
}