for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/**
* Public/private key encryption.
* @author Alex Bilbie <[email protected]>
* @copyright Copyright (c) Alex Bilbie
* @license http://mit-license.org/
* @link https://github.com/thephpleague/oauth2-server
*/
namespace League\OAuth2\Server;
use Defuse\Crypto\Crypto;
trait CryptTrait
{
* @var string
protected $encryptionKey;
* Encrypt data with a private key.
*
* @param string $unencryptedData
* @throws \LogicException
* @return string
protected function encrypt($unencryptedData)
try {
return Crypto::encryptWithPassword($unencryptedData, $this->encryptionKey);
} catch (\Exception $e) {
throw new \LogicException($e->getMessage());
}
* Decrypt data with a public key.
* @param string $encryptedData
protected function decrypt($encryptedData)
return Crypto::decryptWithPassword($encryptedData, $this->encryptionKey);
* Set the encryption key
* @param string $key
public function setEncryptionKey($key = null)
$this->encryptionKey = $key;