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


PHP Crypt::createKeypair方法代码示例

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


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

示例1: __construct

 /**
  * if session is started, check if ownCloud key pair is set up, if not create it
  * @param \OC\Files\View $view
  *
  * @note The ownCloud key pair is used to allow public link sharing even if encryption is enabled
  */
 public function __construct($view)
 {
     $this->view = $view;
     if (!$this->view->is_dir('files_encryption')) {
         $this->view->mkdir('files_encryption');
     }
     $appConfig = \OC::$server->getAppConfig();
     $publicShareKeyId = Helper::getPublicShareKeyId();
     if ($publicShareKeyId === false) {
         $publicShareKeyId = 'pubShare_' . substr(md5(time()), 0, 8);
         $appConfig->setValue('files_encryption', 'publicShareKeyId', $publicShareKeyId);
     }
     if (!Keymanager::publicShareKeyExists($view)) {
         $keypair = Crypt::createKeypair();
         // Save public key
         Keymanager::setPublicKey($keypair['publicKey'], $publicShareKeyId);
         // Encrypt private key empty passphrase
         $cipher = Helper::getCipher();
         $encryptedKey = Crypt::symmetricEncryptFileContent($keypair['privateKey'], '', $cipher);
         if ($encryptedKey) {
             Keymanager::setPrivateSystemKey($encryptedKey, $publicShareKeyId);
         } else {
             \OCP\Util::writeLog('files_encryption', 'Could not create public share keys', \OCP\Util::ERROR);
         }
     }
     if (Helper::isPublicAccess() && !self::getPublicSharePrivateKey()) {
         // Disable encryption proxy to prevent recursive calls
         $proxyStatus = \OC_FileProxy::$enabled;
         \OC_FileProxy::$enabled = false;
         $encryptedKey = Keymanager::getPrivateSystemKey($publicShareKeyId);
         $privateKey = Crypt::decryptPrivateKey($encryptedKey, '');
         self::setPublicSharePrivateKey($privateKey);
         \OC_FileProxy::$enabled = $proxyStatus;
     }
 }
开发者ID:samj1912,项目名称:repo,代码行数:41,代码来源:session.php

示例2: __construct

 /**
  * if session is started, check if ownCloud key pair is set up, if not create it
  * @param \OC\Files\View $view
  *
  * @note The ownCloud key pair is used to allow public link sharing even if encryption is enabled
  */
 public function __construct($view)
 {
     $this->view = $view;
     if (!$this->view->is_dir('owncloud_private_key')) {
         $this->view->mkdir('owncloud_private_key');
     }
     $appConfig = \OC::$server->getAppConfig();
     $publicShareKeyId = $appConfig->getValue('files_encryption', 'publicShareKeyId');
     if ($publicShareKeyId === null) {
         $publicShareKeyId = 'pubShare_' . substr(md5(time()), 0, 8);
         $appConfig->setValue('files_encryption', 'publicShareKeyId', $publicShareKeyId);
     }
     if (!$this->view->file_exists("/public-keys/" . $publicShareKeyId . ".public.key") || !$this->view->file_exists("/owncloud_private_key/" . $publicShareKeyId . ".private.key")) {
         $keypair = Crypt::createKeypair();
         // Disable encryption proxy to prevent recursive calls
         $proxyStatus = \OC_FileProxy::$enabled;
         \OC_FileProxy::$enabled = false;
         // Save public key
         if (!$view->is_dir('/public-keys')) {
             $view->mkdir('/public-keys');
         }
         $this->view->file_put_contents('/public-keys/' . $publicShareKeyId . '.public.key', $keypair['publicKey']);
         // Encrypt private key empty passphrase
         $cipher = \OCA\Encryption\Helper::getCipher();
         $encryptedKey = \OCA\Encryption\Crypt::symmetricEncryptFileContent($keypair['privateKey'], '', $cipher);
         if ($encryptedKey) {
             Keymanager::setPrivateSystemKey($encryptedKey, $publicShareKeyId . '.private.key');
         } else {
             \OCP\Util::writeLog('files_encryption', 'Could not create public share keys', \OCP\Util::ERROR);
         }
         \OC_FileProxy::$enabled = $proxyStatus;
     }
     if (\OCA\Encryption\Helper::isPublicAccess()) {
         // Disable encryption proxy to prevent recursive calls
         $proxyStatus = \OC_FileProxy::$enabled;
         \OC_FileProxy::$enabled = false;
         $encryptedKey = $this->view->file_get_contents('/owncloud_private_key/' . $publicShareKeyId . '.private.key');
         $privateKey = Crypt::decryptPrivateKey($encryptedKey, '');
         $this->setPublicSharePrivateKey($privateKey);
         $this->setInitialized(\OCA\Encryption\Session::INIT_SUCCESSFUL);
         \OC_FileProxy::$enabled = $proxyStatus;
     }
 }
开发者ID:WYSAC,项目名称:oregon-owncloud,代码行数:49,代码来源:session.php

示例3: __construct

 /**
  * @brief if session is started, check if ownCloud key pair is set up, if not create it
  * @param \OC_FilesystemView $view
  *
  * @note The ownCloud key pair is used to allow public link sharing even if encryption is enabled
  */
 public function __construct($view)
 {
     $this->view = $view;
     if (!$this->view->is_dir('owncloud_private_key')) {
         $this->view->mkdir('owncloud_private_key');
     }
     $publicShareKeyId = \OC_Appconfig::getValue('files_encryption', 'publicShareKeyId');
     if ($publicShareKeyId === null) {
         $publicShareKeyId = 'pubShare_' . substr(md5(time()), 0, 8);
         \OC_Appconfig::setValue('files_encryption', 'publicShareKeyId', $publicShareKeyId);
     }
     if (!$this->view->file_exists("/public-keys/" . $publicShareKeyId . ".public.key") || !$this->view->file_exists("/owncloud_private_key/" . $publicShareKeyId . ".private.key")) {
         $keypair = Crypt::createKeypair();
         // Disable encryption proxy to prevent recursive calls
         $proxyStatus = \OC_FileProxy::$enabled;
         \OC_FileProxy::$enabled = false;
         // Save public key
         if (!$view->is_dir('/public-keys')) {
             $view->mkdir('/public-keys');
         }
         $this->view->file_put_contents('/public-keys/' . $publicShareKeyId . '.public.key', $keypair['publicKey']);
         // Encrypt private key empty passphrase
         $encryptedPrivateKey = Crypt::symmetricEncryptFileContent($keypair['privateKey'], '');
         // Save private key
         $this->view->file_put_contents('/owncloud_private_key/' . $publicShareKeyId . '.private.key', $encryptedPrivateKey);
         \OC_FileProxy::$enabled = $proxyStatus;
     }
     if (\OCA\Encryption\Helper::isPublicAccess()) {
         // Disable encryption proxy to prevent recursive calls
         $proxyStatus = \OC_FileProxy::$enabled;
         \OC_FileProxy::$enabled = false;
         $encryptedKey = $this->view->file_get_contents('/owncloud_private_key/' . $publicShareKeyId . '.private.key');
         $privateKey = Crypt::decryptPrivateKey($encryptedKey, '');
         $this->setPublicSharePrivateKey($privateKey);
         \OC_FileProxy::$enabled = $proxyStatus;
     }
 }
开发者ID:hjimmy,项目名称:owncloud,代码行数:43,代码来源:session.php

示例4: setupServerSide

 /**
  * Sets up user folders and keys for serverside encryption
  *
  * @param string $passphrase to encrypt server-stored private key with
  * @return bool
  */
 public function setupServerSide($passphrase = null)
 {
     // Set directories to check / create
     $setUpDirs = array($this->userDir, $this->publicKeyDir, $this->encryptionDir, $this->keyfilesPath, $this->shareKeysPath);
     // Check / create all necessary dirs
     foreach ($setUpDirs as $dirPath) {
         if (!$this->view->file_exists($dirPath)) {
             $this->view->mkdir($dirPath);
         }
     }
     // Create user keypair
     // we should never override a keyfile
     if (!$this->view->file_exists($this->publicKeyPath) && !$this->view->file_exists($this->privateKeyPath)) {
         // Generate keypair
         $keypair = Crypt::createKeypair();
         if ($keypair) {
             \OC_FileProxy::$enabled = false;
             // Encrypt private key with user pwd as passphrase
             $encryptedPrivateKey = Crypt::symmetricEncryptFileContent($keypair['privateKey'], $passphrase, Helper::getCipher());
             // Save key-pair
             if ($encryptedPrivateKey) {
                 $header = crypt::generateHeader();
                 $this->view->file_put_contents($this->privateKeyPath, $header . $encryptedPrivateKey);
                 $this->view->file_put_contents($this->publicKeyPath, $keypair['publicKey']);
             }
             \OC_FileProxy::$enabled = true;
         }
     } else {
         // check if public-key exists but private-key is missing
         if ($this->view->file_exists($this->publicKeyPath) && !$this->view->file_exists($this->privateKeyPath)) {
             \OCP\Util::writeLog('Encryption library', 'public key exists but private key is missing for "' . $this->keyId . '"', \OCP\Util::FATAL);
             return false;
         } else {
             if (!$this->view->file_exists($this->publicKeyPath) && $this->view->file_exists($this->privateKeyPath)) {
                 \OCP\Util::writeLog('Encryption library', 'private key exists but public key is missing for "' . $this->keyId . '"', \OCP\Util::FATAL);
                 return false;
             }
         }
     }
     return true;
 }
开发者ID:Combustible,项目名称:core,代码行数:47,代码来源:util.php

示例5: adminEnableRecovery

 /**
  * enable recovery
  *
  * @param string $recoveryKeyId
  * @param string $recoveryPassword
  * @return bool
  */
 public static function adminEnableRecovery($recoveryKeyId, $recoveryPassword)
 {
     $view = new \OC\Files\View('/');
     $appConfig = \OC::$server->getAppConfig();
     if ($recoveryKeyId === null) {
         $recoveryKeyId = 'recovery_' . substr(md5(time()), 0, 8);
         $appConfig->setValue('files_encryption', 'recoveryKeyId', $recoveryKeyId);
     }
     if (!Keymanager::recoveryKeyExists($view)) {
         $keypair = Crypt::createKeypair();
         // Save public key
         Keymanager::setPublicKey($keypair['publicKey'], $recoveryKeyId);
         $cipher = Helper::getCipher();
         $encryptedKey = Crypt::symmetricEncryptFileContent($keypair['privateKey'], $recoveryPassword, $cipher);
         if ($encryptedKey) {
             Keymanager::setPrivateSystemKey($encryptedKey, $recoveryKeyId);
             // Set recoveryAdmin as enabled
             $appConfig->setValue('files_encryption', 'recoveryAdminEnabled', 1);
             $return = true;
         }
     } else {
         // get recovery key and check the password
         $util = new Util(new \OC\Files\View('/'), \OCP\User::getUser());
         $return = $util->checkRecoveryPassword($recoveryPassword);
         if ($return) {
             $appConfig->setValue('files_encryption', 'recoveryAdminEnabled', 1);
         }
     }
     return $return;
 }
开发者ID:riso,项目名称:owncloud-core,代码行数:37,代码来源:helper.php

示例6: setupServerSide

 /**
  * @brief Sets up user folders and keys for serverside encryption
  *
  * @param string $passphrase to encrypt server-stored private key with
  * @return bool
  */
 public function setupServerSide($passphrase = null)
 {
     // Set directories to check / create
     $setUpDirs = array($this->userDir, $this->userFilesDir, $this->publicKeyDir, $this->encryptionDir, $this->keyfilesPath, $this->shareKeysPath);
     // Check / create all necessary dirs
     foreach ($setUpDirs as $dirPath) {
         if (!$this->view->file_exists($dirPath)) {
             $this->view->mkdir($dirPath);
         }
     }
     // Create user keypair
     // we should never override a keyfile
     if (!$this->view->file_exists($this->publicKeyPath) && !$this->view->file_exists($this->privateKeyPath)) {
         // Generate keypair
         $keypair = Crypt::createKeypair();
         if ($keypair) {
             \OC_FileProxy::$enabled = false;
             // Encrypt private key with user pwd as passphrase
             $encryptedPrivateKey = Crypt::symmetricEncryptFileContent($keypair['privateKey'], $passphrase);
             // Save key-pair
             if ($encryptedPrivateKey) {
                 $this->view->file_put_contents($this->privateKeyPath, $encryptedPrivateKey);
                 $this->view->file_put_contents($this->publicKeyPath, $keypair['publicKey']);
             }
             \OC_FileProxy::$enabled = true;
         }
     } else {
         // check if public-key exists but private-key is missing
         if ($this->view->file_exists($this->publicKeyPath) && !$this->view->file_exists($this->privateKeyPath)) {
             \OCP\Util::writeLog('Encryption library', 'public key exists but private key is missing for "' . $this->keyId . '"', \OCP\Util::FATAL);
             return false;
         } else {
             if (!$this->view->file_exists($this->publicKeyPath) && $this->view->file_exists($this->privateKeyPath)) {
                 \OCP\Util::writeLog('Encryption library', 'private key exists but public key is missing for "' . $this->keyId . '"', \OCP\Util::FATAL);
                 return false;
             }
         }
     }
     // If there's no record for this user's encryption preferences
     if (false === $this->recoveryEnabledForUser()) {
         // create database configuration
         $sql = 'INSERT INTO `*PREFIX*encryption` (`uid`,`mode`,`recovery_enabled`,`migration_status`) VALUES (?,?,?,?)';
         $args = array($this->userId, 'server-side', 0, self::MIGRATION_OPEN);
         $query = \OCP\DB::prepare($sql);
         $query->execute($args);
     }
     return true;
 }
开发者ID:omusico,项目名称:isle-web-framework,代码行数:54,代码来源:util.php

示例7: setPassphrase

 /**
  * Change a user's encryption passphrase
  * @param array $params keys: uid, password
  */
 public static function setPassphrase($params)
 {
     if (\OCP\App::isEnabled('files_encryption') === false) {
         return true;
     }
     // Only attempt to change passphrase if server-side encryption
     // is in use (client-side encryption does not have access to
     // the necessary keys)
     if (Crypt::mode() === 'server') {
         $view = new \OC\Files\View('/');
         $session = new Session($view);
         // Get existing decrypted private key
         $privateKey = $session->getPrivateKey();
         if ($params['uid'] === \OCP\User::getUser() && $privateKey) {
             // Encrypt private key with new user pwd as passphrase
             $encryptedPrivateKey = Crypt::symmetricEncryptFileContent($privateKey, $params['password'], Helper::getCipher());
             // Save private key
             if ($encryptedPrivateKey) {
                 Keymanager::setPrivateKey($encryptedPrivateKey, \OCP\User::getUser());
             } else {
                 \OCP\Util::writeLog('files_encryption', 'Could not update users encryption password', \OCP\Util::ERROR);
             }
             // NOTE: Session does not need to be updated as the
             // private key has not changed, only the passphrase
             // used to decrypt it has changed
         } else {
             // admin changed the password for a different user, create new keys and reencrypt file keys
             $user = $params['uid'];
             $util = new Util($view, $user);
             $recoveryPassword = isset($params['recoveryPassword']) ? $params['recoveryPassword'] : null;
             // we generate new keys if...
             // ...we have a recovery password and the user enabled the recovery key
             // ...encryption was activated for the first time (no keys exists)
             // ...the user doesn't have any files
             if ($util->recoveryEnabledForUser() && $recoveryPassword || !$util->userKeysExists() || !$view->file_exists($user . '/files')) {
                 // backup old keys
                 $util->backupAllKeys('recovery');
                 $newUserPassword = $params['password'];
                 // make sure that the users home is mounted
                 \OC\Files\Filesystem::initMountPoints($user);
                 $keypair = Crypt::createKeypair();
                 // Disable encryption proxy to prevent recursive calls
                 $proxyStatus = \OC_FileProxy::$enabled;
                 \OC_FileProxy::$enabled = false;
                 // Save public key
                 Keymanager::setPublicKey($keypair['publicKey'], $user);
                 // Encrypt private key with new password
                 $encryptedKey = Crypt::symmetricEncryptFileContent($keypair['privateKey'], $newUserPassword, Helper::getCipher());
                 if ($encryptedKey) {
                     Keymanager::setPrivateKey($encryptedKey, $user);
                     if ($recoveryPassword) {
                         // if recovery key is set we can re-encrypt the key files
                         $util = new Util($view, $user);
                         $util->recoverUsersFiles($recoveryPassword);
                     }
                 } else {
                     \OCP\Util::writeLog('files_encryption', 'Could not update users encryption password', \OCP\Util::ERROR);
                 }
                 \OC_FileProxy::$enabled = $proxyStatus;
             }
         }
     }
 }
开发者ID:yheric455042,项目名称:owncloud82,代码行数:67,代码来源:hooks.php


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