Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
crypt decoding doesn't work
  • Hi, So after finally waisting time cause of my own fault, I finally got my website up and running again with RC2.
    But one thing bugs me. The decoding of the crypt class gives me a empty string.
    I use a key which has a length (8) of multiple of 4. Anyone else tried this?
  • Out of curiosity, is there a maximum length of value you can encode and successfully decode?
  • Do not try to manually assign crypto keys. Give the webserver write access to the config file and let the crypt class generate crypto keys. Due to the way keys are generated and encoded, it is very complicated to invent some secure keys yourself. I have to admit the docs are confusing at this point, I have to find the time to correct this.
  • I'm not sure if you got my problem...
    I use the generated keys of fuelphp. So I did give write access and the file has been created. In my decode, I set the key to "false" so it would use the one that has been autogenerated. The encoding works, but not the decoding. It just gives me an empty string.
  • Can you please show some code, so we know what you're talking about?
    I haven't got a clue about what key you're talking, that you are setting to false. Using crypt isn't anything more than
    $string = 'This is a string';
    $encoded = Crypt::encode($string);
    $decoded = Crypt::decode($encoded);
    
    if ($decoded !== $string) echo "Does this happen?";
    
  • I use this in a model:
    public function encryptApiKey($api_key){
      $value = Crypt::encode($api_key, false);
      return $value;
     }
    
     public function decryptApiKey($api_key){
      $value = Crypt::decode($api_key, false);
      return $value;
     }
    

    whether I remove false or not, doesn't change a thing. the api key can be around 60 to 70 characters long though
  • I can't reproduce this. I've copied your two methods into a test controller, and added this test method:
    public function action_crypt()
     {
    $x = 'This is a string This is a string This is a string This is a string This is a string This is a string This is a string This is a string';
    var_dump($x = $this->encryptApiKey($x));
    var_dump($x = $this->decryptApiKey($x));
    
      $this->response->body = '<br /><br /><hr />TEST CONTROLLER - CRYPT METHOD';
     }
    
    This encrypts and decrypts fine. I think your problems are elsewhere. Are you sure the $api_key is the same in both cases? No issue with storing it, no corruption when getting is from the client (if applicable)?
  • My bad, I thought when encrypting it wouldn't enlarge the length of the key (encoded) but it did.
    Almost double! And in my sql I initiated the field to the maximum length of the decoded key. So it only saved the crypted key partially Thanks to your last phrase I managed to get my thougths back in order :)
  • Ah, no. Encrypting something usually requires more space.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion