Conditions | 2 |
Paths | 2 |
Total Lines | 14 |
Code Lines | 9 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
52 | public static function generate() |
||
53 | { |
||
54 | $boxKp = sodium_crypto_box_keypair(); |
||
55 | $obj = new static; |
||
56 | $obj->secret = \base64_encode(sodium_crypto_box_secretkey($boxKp)); |
||
57 | $obj->hash = \hash('sha256', uniqid('__EncryptionKeyPairHash', true)); |
||
58 | $obj->expires_at = \strtotime(static::OBJECT_EXPIRATION_TIME); |
||
59 | |||
60 | if ($obj->save()) { |
||
61 | return $obj; |
||
62 | } |
||
63 | |||
64 | throw new \yii\base\Exception(Yii::t('yrc', 'Failed to generate security tokens')); |
||
65 | } |
||
66 | } |