Prado\Security\TSecurityManager::getEncryptionKey PHP Method

getEncryptionKey() public method

public getEncryptionKey ( ) : string
return string the private key used to encrypt/decrypt data. If the key is not explicitly set, a random one is generated and returned.
    public function getEncryptionKey()
    {
        if (null === $this->_encryptionKey) {
            if (null === ($this->_encryptionKey = $this->getApplication()->getGlobalState(self::STATE_ENCRYPTION_KEY))) {
                $this->_encryptionKey = $this->generateRandomKey();
                $this->getApplication()->setGlobalState(self::STATE_ENCRYPTION_KEY, $this->_encryptionKey, null, true);
            }
        }
        return $this->_encryptionKey;
    }

Usage Example

 public function testEncryptionKey()
 {
     $sec = new TSecurityManager();
     $sec->init(null);
     // Random encryption key
     $valkey = $sec->getEncryptionKey();
     self::assertEquals($valkey, self::$app->getGlobalState(TSecurityManager::STATE_ENCRYPTION_KEY));
     $sec->setEncryptionKey('aKey');
     self::assertEquals('aKey', $sec->getEncryptionKey());
     try {
         $sec->setEncryptionKey('');
         self::fail('Expected TInvalidDataValueException not thrown');
     } catch (TInvalidDataValueException $e) {
     }
 }