コード例 #1
0
 public function postFile_get_contents($path, $data)
 {
     if (self::isEncrypted($path)) {
         $data = OC_Crypt::blockDecrypt($data);
     }
     return $data;
 }
コード例 #2
0
ファイル: proxy.php プロジェクト: noci2012/owncloud
 public function postFile_get_contents($path, $data)
 {
     if (self::isEncrypted($path)) {
         $cached = OC_FileCache_Cached::get($path, '');
         $data = OC_Crypt::blockDecrypt($data, '', $cached['size']);
     }
     return $data;
 }
コード例 #3
0
ファイル: encryption.php プロジェクト: ryanshoover/core
 function testBinary()
 {
     $key = uniqid();
     $file = __DIR__ . '/binary';
     $source = file_get_contents($file);
     //binary file
     $encrypted = OC_Crypt::encrypt($source, $key);
     $decrypted = OC_Crypt::decrypt($encrypted, $key);
     $decrypted = rtrim($decrypted, "");
     $this->assertEqual($decrypted, $source);
     $encrypted = OC_Crypt::blockEncrypt($source, $key);
     $decrypted = OC_Crypt::blockDecrypt($encrypted, $key, strlen($source));
     $this->assertEqual($decrypted, $source);
 }
 public static function changekeypasscode($newpasscode)
 {
     if (OC_User::isLoggedIn()) {
         $username = OC_USER::getUser();
         // read old key
         $key = file_get_contents(OC_Config::getValue("datadirectory") . '/' . $username . '/encryption.key');
         // decrypt key with old passcode
         $key = OC_Crypt::decrypt($key, $_SESSION['user_password']);
         // encrypt again with new passcode
         $key = OC_Crypt::encrypt($key, $newpassword);
         // store the new key
         file_put_contents(OC_Config::getValue("datadirectory") . '/' . $username . '/encryption.key', $key);
         $_SESSION['user_password'] = $newpasscode;
     }
 }
コード例 #5
0
 function testEncryption()
 {
     $key = uniqid();
     $file = OC::$SERVERROOT . '/3rdparty/MDB2.php';
     $source = file_get_contents($file);
     //nice large text file
     $encrypted = OC_Crypt::encrypt($source, $key);
     $decrypted = OC_Crypt::decrypt($encrypted, $key);
     $this->assertNotEqual($encrypted, $source);
     $this->assertEqual($decrypted, $source);
     $chunk = substr($source, 0, 8192);
     $encrypted = OC_Crypt::encrypt($chunk, $key);
     $this->assertEqual(strlen($chunk), strlen($encrypted));
     $decrypted = OC_Crypt::decrypt($encrypted, $key);
     $this->assertEqual($decrypted, $chunk);
     $encrypted = OC_Crypt::blockEncrypt($source, $key);
     $decrypted = OC_Crypt::blockDecrypt($encrypted, $key);
     $this->assertNotEqual($encrypted, $source);
     $this->assertEqual($decrypted, $source);
     $tmpFileEncrypted = OCP\Files::tmpFile();
     OC_Crypt::encryptfile($file, $tmpFileEncrypted, $key);
     $encrypted = file_get_contents($tmpFileEncrypted);
     $decrypted = OC_Crypt::blockDecrypt($encrypted, $key);
     $this->assertNotEqual($encrypted, $source);
     $this->assertEqual($decrypted, $source);
     $tmpFileDecrypted = OCP\Files::tmpFile();
     OC_Crypt::decryptfile($tmpFileEncrypted, $tmpFileDecrypted, $key);
     $decrypted = file_get_contents($tmpFileDecrypted);
     $this->assertEqual($decrypted, $source);
     $file = OC::$SERVERROOT . '/core/img/weather-clear.png';
     $source = file_get_contents($file);
     //binary file
     $encrypted = OC_Crypt::encrypt($source, $key);
     $decrypted = OC_Crypt::decrypt($encrypted, $key);
     $this->assertEqual($decrypted, $source);
     $encrypted = OC_Crypt::blockEncrypt($source, $key);
     $decrypted = OC_Crypt::blockDecrypt($encrypted, $key);
     $this->assertEqual($decrypted, $source);
 }
コード例 #6
0
 private function flush()
 {
     if ($this->writeCache) {
         $encrypted = OC_Crypt::encrypt($this->writeCache);
         fwrite($this->source, $encrypted);
         $this->writeCache = '';
     }
 }
コード例 #7
0
ファイル: crypt.php プロジェクト: noci2012/owncloud
 public static function changekeypasscode($oldPassword, $newPassword)
 {
     if (OCP\User::isLoggedIn()) {
         $username = OCP\USER::getUser();
         $view = new OC_FilesystemView('/' . $username);
         // read old key
         $key = $view->file_get_contents('/encryption.key');
         // decrypt key with old passcode
         $key = OC_Crypt::decrypt($key, $oldPassword);
         // encrypt again with new passcode
         $key = OC_Crypt::encrypt($key, $newPassword);
         // store the new key
         $view->file_put_contents('/encryption.key', $key);
     }
 }