]> git.mxchange.org Git - core.git/blobdiff - framework/main/classes/crypto/class_CryptoHelper.php
Continued:
[core.git] / framework / main / classes / crypto / class_CryptoHelper.php
index 96eb2f9dd7191adbc5f7ec46f636131debfb5ffd..7ef8d3f3adab43aab9ab033cf5e0a86f2ef3fd35 100644 (file)
@@ -5,6 +5,7 @@ namespace Org\Mxchange\CoreFramework\Helper\Crypto;
 // Import framework stuff
 use Org\Mxchange\CoreFramework\Bootstrap\FrameworkBootstrap;
 use Org\Mxchange\CoreFramework\Crypto\Cryptable;
+use Org\Mxchange\CoreFramework\Crypto\RandomNumber\RandomNumberGenerator;
 use Org\Mxchange\CoreFramework\Factory\ObjectFactory;
 use Org\Mxchange\CoreFramework\Object\BaseFrameworkSystem;
 
@@ -50,6 +51,11 @@ class CryptoHelper extends BaseFrameworkSystem implements Cryptable {
         */
        private $salt = '';
 
+       /**
+        * Instance of a RNG
+        */
+       private $rngInstance = NULL;
+
        /**
         * Protected constructor
         *
@@ -95,6 +101,25 @@ class CryptoHelper extends BaseFrameworkSystem implements Cryptable {
                return self::$selfInstance;
        }
 
+       /**
+        * Setter for RNG instance
+        *
+        * @param       $rngInstance    An instance of a random number generator (RNG)
+        * @return      void
+        */
+       protected final function setRngInstance (RandomNumberGenerator $rngInstance) {
+               $this->rngInstance = $rngInstance;
+       }
+
+       /**
+        * Getter for RNG instance
+        *
+        * @return      $rngInstance    An instance of a random number generator (RNG)
+        */
+       public final function getRngInstance () {
+               return $this->rngInstance;
+       }
+
        /**
         * Attaches a crypto stream to this crypto helper by detecting loaded
         * modules.
@@ -106,13 +131,13 @@ class CryptoHelper extends BaseFrameworkSystem implements Cryptable {
                // Do we have openssl/mcrypt loaded?
                if ($this->isPhpExtensionLoaded('mcrypt')) {
                        // Then use it
-                       $this->cryptoStreamInstance = ObjectFactory::createObjectByName('Org\Mxchange\CoreFramework\Stream\Crypto\McryptStream', array($this->getRngInstance()));
+                       $this->cryptoStreamInstance = ObjectFactory::createObjectByConfiguredName('crypto_mcrypt_stream_class', array($this->getRngInstance()));
                } elseif ($this->isPhpExtensionLoaded('openssl')) {
                        // Then use it
-                       $this->cryptoStreamInstance = ObjectFactory::createObjectByName('Org\Mxchange\CoreFramework\Stream\Crypto\OpenSslStream', array($this->getRngInstance()));
+                       $this->cryptoStreamInstance = ObjectFactory::createObjectByConfiguredName('crypto_openssl_stream_class', array($this->getRngInstance()));
                } else {
                        // If nothing works ...
-                       $this->cryptoStreamInstance = ObjectFactory::createObjectByName('Org\Mxchange\CoreFramework\Stream\Crypto\NullCryptoStream');
+                       $this->cryptoStreamInstance = ObjectFactory::createObjectByConfiguredName('crypto_null_stream_class');
                }
        }