public function getMockFileResource($filename = 'test.jpg')
 {
     $hash = sha1(Algorithms::generateRandomBytes(40));
     $resourcePointer = new \TYPO3\Flow\Resource\ResourcePointer($hash);
     $mockResource = $this->getAccessibleMock('TYPO3\\Flow\\Resource\\Resource', array('getResourcePointer'));
     $mockResource->expects($this->any())->method('getResourcePointer')->will($this->returnValue($resourcePointer));
     $mockResource->_set('filename', $filename);
     return $mockResource;
 }
 /**
  * Returns the encryption key from the persistent cache or Data/Persistent directory. If none exists, a new
  * encryption key will be generated and stored in the cache.
  *
  * @return string The configured encryption key stored in Data/Persistent/EncryptionKey
  */
 protected function getEncryptionKey()
 {
     if ($this->encryptionKey === NULL) {
         $this->encryptionKey = $this->cache->get('encryptionKey');
     }
     if ($this->encryptionKey === FALSE && file_exists(FLOW_PATH_DATA . 'Persistent/EncryptionKey')) {
         $this->encryptionKey = file_get_contents(FLOW_PATH_DATA . 'Persistent/EncryptionKey');
     }
     if ($this->encryptionKey === FALSE) {
         $this->encryptionKey = bin2hex(\TYPO3\Flow\Utility\Algorithms::generateRandomBytes(96));
         $this->cache->set('encryptionKey', $this->encryptionKey);
     }
     return $this->encryptionKey;
 }
 /**
  * @test
  */
 public function generateRandomBytesGeneratesRandomBytes()
 {
     $this->assertEquals(20, strlen(Algorithms::generateRandomBytes(20)));
 }
 /**
  * Hash a password for storage using PBKDF2 and the configured parameters.
  * Will use a combination of a random dynamic salt and the given static salt.
  *
  * @param string $password Cleartext password that should be hashed
  * @param string $staticSalt Static salt that will be appended to the random dynamic salt
  * @return string A Base64 encoded string with the derived key (hashed password) and dynamic salt
  */
 public function hashPassword($password, $staticSalt = null)
 {
     $dynamicSalt = \TYPO3\Flow\Utility\Algorithms::generateRandomBytes($this->dynamicSaltLength);
     $result = \TYPO3\Flow\Security\Cryptography\Algorithms::pbkdf2($password, $dynamicSalt . $staticSalt, $this->iterationCount, $this->derivedKeyLength, $this->algorithm);
     return base64_encode($dynamicSalt) . ',' . base64_encode($result);
 }
 /**
  * @return string The configured encryption key stored in Data/Persistent/EncryptionKey
  * @throws \TYPO3\Flow\Security\Exception\MissingConfigurationException
  */
 protected function getEncryptionKey()
 {
     if ($this->encryptionKey === NULL) {
         if (!file_exists(FLOW_PATH_DATA . 'Persistent/EncryptionKey')) {
             file_put_contents(FLOW_PATH_DATA . 'Persistent/EncryptionKey', bin2hex(\TYPO3\Flow\Utility\Algorithms::generateRandomBytes(96)));
         }
         $this->encryptionKey = file_get_contents(FLOW_PATH_DATA . 'Persistent/EncryptionKey');
         if ($this->encryptionKey === FALSE || $this->encryptionKey === '') {
             throw new \TYPO3\Flow\Security\Exception\MissingConfigurationException('No encryption key for the HashService was found and none could be created at "' . FLOW_PATH_DATA . 'Persistent/EncryptionKey"', 1258991855);
         }
     }
     return $this->encryptionKey;
 }
 /**
  * Returns the encryption key from the persistent cache or Data/Persistent directory. If none exists, a new
  * encryption key will be generated and stored in the cache.
  *
  * @return string The configured encryption key stored in Data/Persistent/EncryptionKey
  */
 protected function getEncryptionKey()
 {
     if ($this->encryptionKey === null) {
         $this->encryptionKey = $this->cache->get('encryptionKey');
     }
     if ($this->encryptionKey === false && file_exists(FLOW_PATH_DATA . 'Persistent/EncryptionKey')) {
         $this->encryptionKey = file_get_contents(FLOW_PATH_DATA . 'Persistent/EncryptionKey');
     }
     if ($this->encryptionKey === false) {
         $this->encryptionKey = bin2hex(Utility\Algorithms::generateRandomBytes(48));
         $this->cache->set('encryptionKey', $this->encryptionKey);
     }
     return $this->encryptionKey;
 }