Ignore:
Timestamp:
Nov 13, 2011, 8:33:09 PM (12 years ago)
Author:
mistic100
Message:

fix key generation function when mcrypt is disabled, fix display on some themes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/Subscribe_to_comments/include/functions.inc.php

    r12609 r12620  
    371371
    372372/**
    373  * crypt a string using mcrypt extension or a binary method
     373 * crypt a string using mcrypt extension or
     374 * http://stackoverflow.com/questions/800922/how-to-encrypt-string-without-mcrypt-library-in-php/802957#802957
    374375 * @param string value to crypt
    375376 * @param string key
     
    382383    $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
    383384    $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
    384     $value = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $value, MCRYPT_MODE_ECB, $iv);
     385    $result = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $value, MCRYPT_MODE_ECB, $iv);
    385386  }
    386387  else
    387388  {
    388     $value = $value ^ $key; // binary XOR operation
    389   }
    390  
    391   $value = base64url_encode($value);
    392   return trim($value);
     389    $result = null;
     390    for($i = 0; $i < strlen($value); $i++)
     391    {
     392      $char = substr($value, $i, 1);
     393      $keychar = substr($key, ($i % strlen($key))-1, 1);
     394      $char = chr(ord($char) + ord($keychar));
     395      $result .= $char;
     396    }
     397  }
     398 
     399  $result = base64url_encode($result);
     400  return trim($result);
    393401}
    394402
     
    407415    $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
    408416    $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
    409     $value = mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key, $value, MCRYPT_MODE_ECB, $iv);
     417    $result = mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key, $value, MCRYPT_MODE_ECB, $iv);
    410418  }
    411419  else
    412420  {
    413     $value = $value ^ $key; // binary XOR operation
    414   }
    415  
    416   return trim($value);
    417 }
    418 
     421    $result = null;
     422    for($i = 0; $i < strlen($value); $i++)
     423    {
     424      $char = substr($value, $i, 1);
     425      $keychar = substr($key, ($i % strlen($key))-1, 1);
     426      $char = chr(ord($char) - ord($keychar));
     427      $result .= $char;
     428    }
     429  }
     430 
     431  return trim($result);
     432}
    419433
    420434/**
Note: See TracChangeset for help on using the changeset viewer.