Link to home
Start Free TrialLog in
Avatar of Jack_son_
Jack_son_Flag for Afghanistan

asked on

Encrypt static variables

I have a custom PHP application, and I have a few static values that work with API's and will not change.  I need to keep them in a file for testing but want to encrypt these values, so maybe need both encrypt and decrypt file.  Let me know if you have seen this before
SOLUTION
Avatar of gplana
gplana
Flag of Spain image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Jack_son_

ASKER

if someone gets on the server ever and gets access to the keys, it would cause havoc, thats the main reason; so encrypting them is important.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Understood; I like this, so after I encrypt, to decrypt I would use this function in my code?

 public function decrypt($text)
    {
        // DECODE THE DATA INTO THE BINARY ENCRYPTED STRING
        $text = base64_decode($text);

        // DECRYPT THE STRING
        $data = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $this->key, $text, MCRYPT_MODE_ECB, $this->iv);

        // REMOVE END OF TEXT DELIMITER
        $data = explode($this->eot, $data);
        return $data[0];
> if someone gets on the server ever and gets access ... it would cause havoc, thats the main reason; so encrypting them is important.

if someone gets to the server and can read your code, it doesn' matter if the file is encrypted or not, unless the en-/decryption **always** requieres to enter a passphrase manually
is this what you want?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Yes it is a dedicated server; idea is the application will grab these static values to run an API. I guess what I'm trying to get is how to decrypt, I'm assuming just call the class?
The correct terminology would probably be to "call a method on an object instance of the class."  If the class definition is not obvious to you, we might be best off to return to this:  Maybe if you can describe the information you're trying to protect and the "havoc" you're concerned about we could offer some suggestions that would make sense for your application. In other words, encryption is not the only thing you can consider for application security.  What API are you trying to protect?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Okay, thanks.  How can I allow it to support longer strings?  Also, once I get the string encrypted, does it create a decryption key or how do I get it decrypted.  The idea is I can encrypt these values and save them securely, then I need the function to decrypt or provide a decryption key?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Pronouns are the enemy of human communication.  Example: How can I allow it to support longer strings?  By it do you mean the key, the source data, the EOT or what, exactly?

Encryption as illustrated in my example depends on the key and the EOT string.  These must be known to both sides of the process.

And I still think you may be overthinking this whole process.  Please tell us about the information you're trying to protect.  What is it in information terms -- strings?  how long? etc.  What is its value in economic terms?  Would a breach cost thousands of dollars?  thousands of lives?

Armed with a little more information we can possibly offer common sense solutions and references that might help you make the best decision.

Thanks, ~Ray
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial