Renamed Registry -> GenericRegistry to make it clear that this registry does
[core.git] / framework / main / classes / crypto / class_CryptoHelper.php
index 153f4d4f781daacb89c535f6cf5b73e8db031ff2..1bf22a341543eae677c2a64549013fa942f18bb5 100644 (file)
@@ -1,10 +1,11 @@
 <?php
 // Own namespace
-namespace CoreFramework\Helper\Crypto;
+namespace Org\Mxchange\CoreFramework\Helper\Crypto;
 
 // Import framework stuff
-use CoreFramework\Factory\ObjectFactory;
-use CoreFramework\Object\BaseFrameworkSystem;
+use Org\Mxchange\CoreFramework\Crypto\Cryptable;
+use Org\Mxchange\CoreFramework\Factory\ObjectFactory;
+use Org\Mxchange\CoreFramework\Object\BaseFrameworkSystem;
 
 /**
  * A helper class for cryptographical things like hashing passwords and so on
@@ -100,13 +101,17 @@ class CryptoHelper extends BaseFrameworkSystem implements Cryptable {
         * @return      void
         */
        protected function attachCryptoStream () {
-               // Do we have mcrypt loaded?
+               // @TODO Maybe rewrite this with DirectoryIterator, similar to Compressor thing?
+               // Do we have openssl/mcrypt loaded?
                if ($this->isPhpExtensionLoaded('mcrypt')) {
                        // Then use it
-                       $this->cryptoStreamInstance = ObjectFactory::createObjectByName('McryptStream', array($this->getRngInstance()));
+                       $this->cryptoStreamInstance = ObjectFactory::createObjectByName('Org\Mxchange\CoreFramework\Stream\Crypto\McryptStream', array($this->getRngInstance()));
+               } elseif ($this->isPhpExtensionLoaded('openssl')) {
+                       // Then use it
+                       $this->cryptoStreamInstance = ObjectFactory::createObjectByName('Org\Mxchange\CoreFramework\Stream\Crypto\OpenSslStream', array($this->getRngInstance()));
                } else {
                        // If nothing works ...
-                       $this->cryptoStreamInstance = ObjectFactory::createObjectByName('NullCryptoStream');
+                       $this->cryptoStreamInstance = ObjectFactory::createObjectByName('Org\Mxchange\CoreFramework\Stream\Crypto\NullCryptoStream');
                }
        }
 
@@ -150,7 +155,7 @@ class CryptoHelper extends BaseFrameworkSystem implements Cryptable {
                $uuid = '';
 
                // Is the UUID extension loaded and enabled? (see pecl)
-               if ($this->getConfigInstance()->getConfigEntry('extension_uuid_loaded') === TRUE) {
+               if ($this->getConfigInstance()->getConfigEntry('extension_uuid_loaded') === true) {
                        // Then add it as well
                        $uuid = uuid_create();
                } // END - if
@@ -170,7 +175,7 @@ class CryptoHelper extends BaseFrameworkSystem implements Cryptable {
         * @param       $withFixed      Whether to include a fixed salt (not recommended in p2p applications)
         * @return      $hashed         The hashed and salted string
         */
-       public function hashString ($str, $oldHash = '', $withFixed = TRUE) {
+       public function hashString ($str, $oldHash = '', $withFixed = true) {
                // Cast the string
                $str = (string) $str;
 
@@ -188,7 +193,7 @@ class CryptoHelper extends BaseFrameworkSystem implements Cryptable {
 
                // Hash the password with salt
                //* DEBUG: */ echo "salt=".$salt."/plain=".$str."<br />\n";
-               if ($withFixed === TRUE) {
+               if ($withFixed === true) {
                        // Use additional fixed salt
                        $hashed = $salt . md5(sprintf($this->getConfigInstance()->getConfigEntry('hash_extra_mask'),
                                $salt,