Create an instance of a crypt driver.


@throws \Webiny\Component\StdLib\Exception\Exception
@return CryptInterface
495758
static function getInstance()
    {
        $driver = static::getLibrary();

        try {
            $instance = new $driver();
        } catch (\Exception $e) {
            throw new Exception('Unable to create an instance of ' . $driver);
        }

        if (!self::isInstanceOf($instance, CryptInterface::class)) {
            throw new Exception(Exception::MSG_INVALID_ARG, ['driver', CryptInterface::class]);
        }

        return $instance;
    }
308191
public final synchronized CryptoHelper
    lazyGetCryptoHelper() throws Exception {
    String beanName = getCryptoHelperName();
    CryptoHelper cryptoHelper =
      (CryptoHelper) getBeansMap().get(beanName);
    if (cryptoHelper == null) {
      cryptoHelper = new CryptoHelper();
      File webAppDir = new File(getWebAppPath());
      cryptoHelper.setKsDirPath(webAppDir.getParent() + File.separator + "ks");
      File peDir = new File(webAppDir.getParent()
        + File.separator + "pub-exch");
      if (!peDir.exists() && !peDir.mkdir()) {
        throw new Exception("Can't create directory: " + peDir);
      }
      cryptoHelper.setPublicKeyDir(peDir.getPath());
      getBeansMap().put(beanName, cryptoHelper);
      lazyGetLogger().info(null, FactoryAccAppBeansSqlite.class, beanName
        + " has been created.");
    }
    return cryptoHelper;
  }
1194083
public static function create()
    {
        return parent::create()
            ->setSerializationContextFactory(array(self::class, 'createDefaultSerializationContext'))
            ->addDefaultHandlers()
            ->configureListeners(function (EventDispatcher $dispatcher) {
                $proxySubscriber = new DoctrineProxySubscriber(false);
                $dispatcher->addSubscriber($proxySubscriber);
            })
            ->configureHandlers(function (HandlerRegistryInterface $handlerRegistry) {
                $proxyHandler = new DoctrineProxyHandler();
                $handlerRegistry->registerSubscribingHandler($proxyHandler);
            })
        ;
    }
729871
public function getEccKey() : PublicKeyInterface
    {
        $math = EccFactory::getAdapter();
        $generator = EccFactory::getNistCurves()->generator256();
        $pointSerializer = new UncompressedPointSerializer($math);
        $point = $pointSerializer->unserialize($generator->getCurve(), bin2hex($this->getRawKeyMaterial()));

        return $generator->getPublicKeyFrom($point->getX(), $point->getY(), $generator->getOrder());
    }
971961
public static function create(): GUID
    {
        $guid = \random_bytes(16);

        // Reset version byte to version 4 (0100)
        $guid[6] = chr(ord($guid[6]) & 0x0f | 0x40);

        $guid[8] = chr(ord($guid[8]) & 0x3f | 0x80);

        return new static($guid);
    }
677993
protected function getCrypt()
    {
        static $crypt;

        if (!$crypt) {
            if (empty($this->encodingAESKey) || empty($this->token)) {
                throw new Exception("加密模式下 'encodingAESKey' 与 'token' 都不能为空！");
            }

            $crypt = new Crypt($this->appId, $this->token, $this->encodingAESKey);
        }

        return $crypt;
    }
1152926
public function getCrypto()
    {
        if (!file_exists($this->keyPath)) {
            throw new CryptoException(sprintf(self::ERR_KEY_PATH, $this->keyPath));
        }

        $key = call_user_func($this->keyLoader, $this->keyPath);
        $key = trim($key);

        if (strlen($key) % 2 !== 0) {
            throw new CryptoException(sprintf(self::ERR_INVALID_KEY, $this->keyPath));
        }

        $key = hex2bin($key);

        return new Encryption($key);
    }
741457
protected static function createGeneral()
	{
	    $roleModel = new \erdiko\users\models\Role;
        $roleGeneral = $roleModel->findByName('general');
        if (empty($roleGeneral)) {
            throw new \Exception('Role general not found.');
        }

		$entity = new entity();
		$entity->setId( 0 );
		$entity->setRole( $roleGeneral->getId() );
		$entity->setName( 'user' );
		$entity->setEmail( 'user' );
		return $entity;
	}
233499
protected function createPasswordHash( $password )
    {
        if ( function_exists( 'password_hash' ) )
        {
            return password_hash( $password, PASSWORD_DEFAULT );
        }

        if ( ! defined( 'CRYPT_BLOWFISH' ) )
        {
            throw new Exception\RuntimeException( sprintf(
                '%s: CRYPT_BLOWFISH algorithm must be enabled',
                __METHOD__
            ) );
        }

        return crypt(
            $password,
            ( version_compare( PHP_VERSION, '5.3.7' ) >= 0 ? '$2y' : '$2a' ) .
            '$10$' . $this->createPasswordSalt() . '$'
        );
    }
381907
public function createInstance()
    {
        $classname = $this->getEngineClassname();

        if (!class_exists($classname)) {
            throw new \Exception(
                sprintf('Unable to locate class %s', $classname)
            );
        }

        return new $classname();
    }
894532
public function create() {
		$ssoClient = new \Flowpack\SingleSignOn\Client\Domain\Model\SsoClient();
		if ((string)$this->clientServiceBaseUri === '') {
			throw new Exception('Missing Flowpack.SingleSignOn.Client.client.serviceBaseUri setting', 1351075078);
		}
		$ssoClient->setServiceBaseUri($this->clientServiceBaseUri);
		if ((string)$this->clientPublicKeyFingerprint === '') {
			throw new Exception('Missing Flowpack.SingleSignOn.Client.client.publicKeyFingerprint setting', 1351075159);
		}
		$ssoClient->setPublicKeyFingerprint($this->clientPublicKeyFingerprint);
		return $ssoClient;
	}
383927
public static function keyCreate(){
		return base64_encode(mcrypt_create_iv(
			 mcrypt_get_key_size(self::$crypt_cipher,self::$crypt_mode)
			,self::$crypt_rand
		));
	}
538606
private function createDriver()
    {
        if (is_string($this->config['driver'])) {
            $drivername = ucfirst($this->config['driver']);
            $driverclass = sprintf('Intervention\\Image\\%s\\Driver', $drivername);

            if (class_exists($driverclass)) {
                return new $driverclass;
            }

            throw new \Intervention\Image\Exception\NotSupportedException(
                "Driver ({$drivername}) could not be instantiated."
            );
        }

        if ($this->config['driver'] instanceof AbstractDriver) {
            return $this->config['driver'];
        }

        throw new \Intervention\Image\Exception\NotSupportedException(
            "Unknown driver type."
        );
    }
611580
public function connect()
    {
        $sslContext = stream_context_create([
            'ssl' => [
                'allow_self_signed' => true,
                'verify_peer'       => true,
                'verify_peer_name'  => false,
                'cafile'            => $this->serverCertificate,
                'local_cert'        => $this->localCertificate,
                'local_pk'          => $this->privateKey,
                'passphrase'        => $this->privateKeyPass,
                'crypto_method'     => STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT
            ]
        ]);

        set_error_handler(function ($err_severity, $err_msg) {
            throw new RuntimeException($err_msg);
        });

        $this->_connection = stream_socket_client("tls://{$this->host}:{$this->port}",
            $errno,
            $errstr,
            30,
            STREAM_CLIENT_CONNECT,
            $sslContext
        );
        restore_error_handler();

        if ( ! $this->_connection) {
            throw new RuntimeException('Could not connect to host: '
                . $this->host
                . ', port:' . $this->port
                . "(Error $errno: $errstr)");
        }

        stream_set_blocking($this->_connection, true);
    }
869234
protected function openCryptModule()
	{
		if(extension_loaded('mcrypt'))
		{
			if(is_array($this->cryptAlgorithm))
				$module=@call_user_func_array('mcrypt_module_open',$this->cryptAlgorithm);
			else
				$module=@mcrypt_module_open($this->cryptAlgorithm,'', MCRYPT_MODE_CBC,'');

			if($module===false)
				throw new CException(Yii::t('yii','Failed to initialize the mcrypt module.'));

			return $module;
		}
		else
			throw new CException(Yii::t('yii','CSecurityManager requires PHP mcrypt extension to be loaded in order to use data encryption feature.'));
	}
384108
public function createInstance()
    {
        $classname = $this->getPlatformClassname();

        if (!class_exists($classname)) {
            throw new \Exception(
                sprintf('Unable to locate class %s', $classname)
            );
        }

        return new $classname();
    }
1281703
public function connect(): DriverInterface
    {
        try {
            $connection = new PDO(
                $this->getDsn(),
                $this->getParam('username'),
                $this->getParam('password'),
                $this->getOptions()
            );
            $this->setInstance($connection);

        } catch (SQLException $e) {
            // __construct
        }

        return $this;
    }