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


PHP Crypt::legacyBlockDecrypt方法代码示例

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


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

示例1: postFile_get_contents

 /**
  * @param string $path Path of file from which has been read
  * @param string $data Data that has been read from file
  */
 public function postFile_get_contents($path, $data)
 {
     $plainData = null;
     $view = new \OC_FilesystemView('/');
     // init session
     $session = new \OCA\Encryption\Session($view);
     // If data is a catfile
     if (Crypt::mode() === 'server' && Crypt::isCatfileContent($data)) {
         $handle = fopen('crypt://' . $path, 'r');
         if (is_resource($handle)) {
             while (($plainDataChunk = fgets($handle, 8192)) !== false) {
                 $plainData .= $plainDataChunk;
             }
         }
     } elseif (Crypt::mode() == 'server' && \OC::$session->exists('legacyenckey') && Crypt::isEncryptedMeta($path)) {
         // Disable encryption proxy to prevent recursive calls
         $proxyStatus = \OC_FileProxy::$enabled;
         \OC_FileProxy::$enabled = false;
         $plainData = Crypt::legacyBlockDecrypt($data, $session->getLegacyKey());
         \OC_FileProxy::$enabled = $proxyStatus;
     }
     if (!isset($plainData)) {
         $plainData = $data;
     }
     return $plainData;
 }
开发者ID:hjimmy,项目名称:owncloud,代码行数:30,代码来源:proxy.php

示例2: encryptAll

 /**
  * @brief Encrypt all files in a directory
  * @param string $dirPath the directory whose files will be encrypted
  * @param null $legacyPassphrase
  * @param null $newPassphrase
  * @return bool
  * @note Encryption is recursive
  */
 public function encryptAll($dirPath, $legacyPassphrase = null, $newPassphrase = null)
 {
     $found = $this->findEncFiles($dirPath);
     if ($found) {
         // Disable proxy to prevent file being encrypted twice
         \OC_FileProxy::$enabled = false;
         $versionStatus = \OCP\App::isEnabled('files_versions');
         \OC_App::disable('files_versions');
         $encryptedFiles = array();
         // Encrypt unencrypted files
         foreach ($found['plain'] as $plainFile) {
             //get file info
             $fileInfo = \OC\Files\Filesystem::getFileInfo($plainFile['path']);
             //relative to data/<user>/file
             $relPath = $plainFile['path'];
             //relative to /data
             $rawPath = '/' . $this->userId . '/files/' . $plainFile['path'];
             // keep timestamp
             $timestamp = $fileInfo['mtime'];
             // Open plain file handle for binary reading
             $plainHandle = $this->view->fopen($rawPath, 'rb');
             // Open enc file handle for binary writing, with same filename as original plain file
             $encHandle = fopen('crypt://' . $rawPath . '.part', 'wb');
             if (is_resource($encHandle)) {
                 // Move plain file to a temporary location
                 $size = stream_copy_to_stream($plainHandle, $encHandle);
                 fclose($encHandle);
                 fclose($plainHandle);
                 $fakeRoot = $this->view->getRoot();
                 $this->view->chroot('/' . $this->userId . '/files');
                 $this->view->rename($relPath . '.part', $relPath);
                 // set timestamp
                 $this->view->touch($relPath, $timestamp);
                 $encSize = $this->view->filesize($relPath);
                 $this->view->chroot($fakeRoot);
                 // Add the file to the cache
                 \OC\Files\Filesystem::putFileInfo($relPath, array('encrypted' => true, 'size' => $encSize, 'unencrypted_size' => $size, 'etag' => $fileInfo['etag']));
                 $encryptedFiles[] = $relPath;
             }
         }
         // Encrypt legacy encrypted files
         if (!empty($legacyPassphrase) && !empty($newPassphrase)) {
             foreach ($found['legacy'] as $legacyFile) {
                 // Fetch data from file
                 $legacyData = $this->view->file_get_contents($legacyFile['path']);
                 // decrypt data, generate catfile
                 $decrypted = Crypt::legacyBlockDecrypt($legacyData, $legacyPassphrase);
                 $rawPath = $legacyFile['path'];
                 // enable proxy the ensure encryption is handled
                 \OC_FileProxy::$enabled = true;
                 // Open enc file handle for binary writing, with same filename as original plain file
                 $encHandle = $this->view->fopen($rawPath, 'wb');
                 if (is_resource($encHandle)) {
                     // write data to stream
                     fwrite($encHandle, $decrypted);
                     // close stream
                     fclose($encHandle);
                 }
                 // disable proxy to prevent file being encrypted twice
                 \OC_FileProxy::$enabled = false;
             }
         }
         \OC_FileProxy::$enabled = true;
         if ($versionStatus) {
             \OC_App::enable('files_versions');
         }
         $this->encryptVersions($encryptedFiles);
         // If files were found, return true
         return true;
     } else {
         // If no files were found, return false
         return false;
     }
 }
开发者ID:omusico,项目名称:isle-web-framework,代码行数:82,代码来源:util.php


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