当前位置: 首页>>代码示例>>PHP>>正文


PHP Crypt::symmetricDecryptFileContent方法代码示例

本文整理汇总了PHP中Crypt::symmetricDecryptFileContent方法的典型用法代码示例。如果您正苦于以下问题:PHP Crypt::symmetricDecryptFileContent方法的具体用法?PHP Crypt::symmetricDecryptFileContent怎么用?PHP Crypt::symmetricDecryptFileContent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Crypt的用法示例。


在下文中一共展示了Crypt::symmetricDecryptFileContent方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: stream_read

 /**
  * @param int $count
  * @return bool|string
  * @throws \Exception
  */
 public function stream_read($count)
 {
     $this->writeCache = '';
     if ($count !== 8192) {
         // $count will always be 8192 https://bugs.php.net/bug.php?id=21641
         // This makes this function a lot simpler, but will break this class if the above 'bug' gets 'fixed'
         \OCP\Util::writeLog('Encryption library', 'PHP "bug" 21641 no longer holds, decryption system requires refactoring', \OCP\Util::FATAL);
         die;
     }
     // Get the data from the file handle
     $data = fread($this->handle, $count);
     $result = null;
     if (strlen($data)) {
         if (!$this->getKey()) {
             // Error! We don't have a key to decrypt the file with
             throw new \Exception('Encryption key not found for "' . $this->rawPath . '" during attempted read via stream');
         } else {
             // Decrypt data
             $result = Crypt::symmetricDecryptFileContent($data, $this->plainKey);
         }
     }
     return $result;
 }
开发者ID:olucao,项目名称:owncloud-core,代码行数:28,代码来源:stream.php

示例2: getFileSize

 /**
  * get the file size of the unencrypted file
  * @param string $path absolute path
  * @return bool
  */
 public function getFileSize($path)
 {
     $result = 0;
     // Disable encryption proxy to prevent recursive calls
     $proxyStatus = \OC_FileProxy::$enabled;
     \OC_FileProxy::$enabled = false;
     // split the path parts
     $pathParts = explode('/', $path);
     if (isset($pathParts[2]) && $pathParts[2] === 'files' && $this->view->file_exists($path) && $this->isEncryptedPath($path)) {
         $cipher = 'AES-128-CFB';
         $realSize = 0;
         // get the size from filesystem
         $size = $this->view->filesize($path);
         // open stream
         $stream = $this->view->fopen($path, "r");
         if (is_resource($stream)) {
             // if the file contains a encryption header we
             // we set the cipher
             // and we update the size
             if ($this->containHeader($path)) {
                 $data = fread($stream, Crypt::BLOCKSIZE);
                 $header = Crypt::parseHeader($data);
                 $cipher = Crypt::getCipher($header);
                 $size -= Crypt::BLOCKSIZE;
             }
             // fast path, else the calculation for $lastChunkNr is bogus
             if ($size === 0) {
                 \OC_FileProxy::$enabled = $proxyStatus;
                 return 0;
             }
             // calculate last chunk nr
             // next highest is end of chunks, one subtracted is last one
             // we have to read the last chunk, we can't just calculate it (because of padding etc)
             $lastChunkNr = ceil($size / Crypt::BLOCKSIZE) - 1;
             // calculate last chunk position
             $lastChunkPos = $lastChunkNr * Crypt::BLOCKSIZE;
             // get the content of the last chunk
             if (@fseek($stream, $lastChunkPos, SEEK_CUR) === 0) {
                 $realSize += $lastChunkNr * 6126;
             }
             $lastChunkContentEncrypted = '';
             $count = Crypt::BLOCKSIZE;
             while ($count > 0) {
                 $data = fread($stream, Crypt::BLOCKSIZE);
                 $count = strlen($data);
                 $lastChunkContentEncrypted .= $data;
                 if (strlen($lastChunkContentEncrypted) > Crypt::BLOCKSIZE) {
                     $realSize += 6126;
                     $lastChunkContentEncrypted = substr($lastChunkContentEncrypted, Crypt::BLOCKSIZE);
                 }
             }
             fclose($stream);
             $relPath = Helper::stripUserFilesPath($path);
             $shareKey = Keymanager::getShareKey($this->view, $this->keyId, $this, $relPath);
             if ($shareKey === false) {
                 \OC_FileProxy::$enabled = $proxyStatus;
                 return $result;
             }
             $session = new Session($this->view);
             $privateKey = $session->getPrivateKey();
             $plainKeyfile = $this->decryptKeyfile($relPath, $privateKey);
             $plainKey = Crypt::multiKeyDecrypt($plainKeyfile, $shareKey, $privateKey);
             $lastChunkContent = Crypt::symmetricDecryptFileContent($lastChunkContentEncrypted, $plainKey, $cipher);
             // calc the real file size with the size of the last chunk
             $realSize += strlen($lastChunkContent);
             // store file size
             $result = $realSize;
         }
     }
     \OC_FileProxy::$enabled = $proxyStatus;
     return $result;
 }
开发者ID:riso,项目名称:owncloud-core,代码行数:77,代码来源:util.php

示例3: stream_read

 /**
  * @param int $count
  * @return bool|string
  * @throws \OCA\Encryption\Exceptions\EncryptionException
  */
 public function stream_read($count)
 {
     $this->writeCache = '';
     if ($count !== Crypt::BLOCKSIZE) {
         \OCP\Util::writeLog('Encryption library', 'PHP "bug" 21641 no longer holds, decryption system requires refactoring', \OCP\Util::FATAL);
         throw new \OCA\Encryption\Exceptions\EncryptionException('expected a blog size of 8192 byte', 20);
     }
     // Get the data from the file handle
     $data = fread($this->handle, $count);
     // if this block contained the header we move on to the next block
     if (Crypt::isHeader($data)) {
         $data = fread($this->handle, $count);
     }
     $result = null;
     if (strlen($data)) {
         if (!$this->getKey()) {
             // Error! We don't have a key to decrypt the file with
             throw new \Exception('Encryption key not found for "' . $this->rawPath . '" during attempted read via stream');
         } else {
             // Decrypt data
             $result = Crypt::symmetricDecryptFileContent($data, $this->plainKey, $this->cipher);
         }
     }
     return $result;
 }
开发者ID:Combustible,项目名称:core,代码行数:30,代码来源:stream.php


注:本文中的Crypt::symmetricDecryptFileContent方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。