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; } }
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); }
private function flush() { if ($this->writeCache) { $encrypted = OC_Crypt::encrypt($this->writeCache); fwrite($this->source, $encrypted); $this->writeCache = ''; } }
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); } }