public function testEncryption() { $availableCiphers = PSL\Encrypter::getSupportedCiphers(); $availableModes = PSL\Encrypter::getSupportedModes(); $e = new PSL\Encrypter(); $key = 'a test key'; $plainText = 'some plain text'; foreach ($availableCiphers as $cipher) { foreach ($availableModes as $mode) { $cipherText = $e->encrypt($cipher, $key, $plainText, $mode); if ($cipherText != false) { $plainTextDeciphered = $e->decrypt($cipherText, $key); $this->assertTrue($plainText === $plainTextDeciphered, "Deciphered text did not match ({$cipher}, {$mode})!"); } } } }
/* YII EXAMPLE ACTION */ function actionRegisterUser() { $user = new User(); $user->firstName = 'example'; if ($user->save()) { Yii::app()->rbac->assignRole($user->id, 'authenticated'); } } exit; define('PSL_RANDOM_GENERATOR', 'capicom'); var_dump(PSL\Randomizer::getRandomBytes(1), PSL\Randomizer::$generatorUsed); exit; $availableCiphers = PSL\Encrypter::getSupportedCiphers(); $availableModes = PSL\Encrypter::getSupportedModes(); $enc = new PSL\Encrypter(); $key = 'asdfgha test key'; $plainText = 'some plain text'; foreach ($availableCiphers as $cipher) { foreach ($availableModes as $mode) { try { $cipherText = $enc->encrypt($cipher, $plainText, $key, $mode); if ($cipherText != false) { $plainTextDeciphered = $enc->decrypt($cipherText, $key); } } catch (Exception $e) { echo "<br />" . $e->getMessage() . "<br />"; } echo "{$cipher} ({$mode}): {$cipherText}<br />"; flush(); }