Php base_64 encryption does it help?

Discussion in 'PHP' started by hexadesigns, Apr 29, 2009.

  1. #1
    Hi,

    I am trying to protect a fragment of my php code. I will not be using Ioncube, Zend or Codelock, because obviously that will like carrying a book on an 18 wheeler. So as far as I can see the only option is base_64 encryption but then it will be very easy for someone to decipher the actual code.

    Does anyone have an idea how to use base_64 with a hashkey or salt and suceesfully encrypt the code.

    For example

    <?php echo 'Hello World'; ?> will be encoded as

    <?php eval(gzinflate(base64_decode('encryptedcodewithahash'))); ?>

    Any help is appreciated. Thank you!
     
    hexadesigns, Apr 29, 2009 IP
  2. johnvixen

    johnvixen Active Member

    Messages:
    256
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    60
    #2
    Well, base_64 is always decryptable, saying that so is Ioncube and Zend.
    My advice is that you keep your SALT in an include file in a root folder not accessible by the web.

    Here's a stable encryption class i use.

    
    
    include("/var/root/to/your/salt/key.inc.php");
    
    // or $key = "bigcheese";
    
    function encrypt($data)
    	{
    	  global $key;
             $iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB), MCRYPT_RAND);
    	  $data = mcrypt_encrypt(MCRYPT_RIJNDAEL_256,$key,$data,MCRYPT_MODE_ECB,$iv);
    	  $data = base64_encode($data); 
    	  return $data;
    	}
    	
    function decrypt($data) 
    	{
    	  global $key;
    	  $iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB), MCRYPT_RAND);
          $data = base64_decode($data); 
    	  $data = mcrypt_decrypt(MCRYPT_RIJNDAEL_256,$key,$data, MCRYPT_MODE_ECB,$iv);
    	  return rtrim($data,"\0");
    	}
    
    
    Code (markup):
     
    johnvixen, Apr 29, 2009 IP
  3. SmallPotatoes

    SmallPotatoes Peon

    Messages:
    1,321
    Likes Received:
    41
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Base 64 is NOT encryption, it is encoding. It is just as easily reversed as it is applied. It does not prevent people from seeing what has been encoded, nor was it intended to; quite the opposite.

    Johnvixen's code doesn't prevent your material from being seen by anyone who has the ability to install PHP files on the server.
     
    SmallPotatoes, Apr 29, 2009 IP
  4. tguillea

    tguillea Active Member

    Messages:
    229
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    90
    #4
    Your best option is to put it above the html folder (like a root folder or data).

    Good luck!
     
    tguillea, Apr 29, 2009 IP
  5. nayes84

    nayes84 Member

    Messages:
    34
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    43
    #5
    you need to use encryption mechanism like zend encoding to encode your files. though it cost a lot of money to get license for zend encoder
     
    nayes84, May 1, 2009 IP