Sunday 15 January 2012

php - Encryption - Decryption, Database -


I have created two functions such as encryption and decryption

  function encryption ($ X) {$ Key = 'supercceptive'; $ Encrypted = encrypt_encrypt (MCRYPT_RIJNDAEL_256, $ key, $ x, MCRYPT_MODE_ECB); $ Encrypted return; } Function decryption ($ y) {$ key = 'SuperSecretKey'; $ Decrypted = mcrypt_decrypt (MCRYPT_RIJNDAEL_256, $ key, $ y, MCRYPT_MODE_ECB); Return $ decrypted; }   

I got the encrypted password to work properly on my database, when I recover the password from the database, I get an encrypted password like this

  $ dpass = "Select password from persons where email = '". $ _POST ['name'] "'"; $ Rpass = mysql_query ($ dpass); $ Line = mysql_fetch_array ($ rpass); $ Lpass = $ line ['password']; Echo $ lpass;   

But the problem is that when U uses decryption func

  $ d_pass = decryption ($ lpass); Echo $ d_pass;   

Does not this teach me the same text that I used for the password? Can you tell me what is the problem?

try it

  function encryption ($ x) {$ key = 'SuperSecretKey'; $ Encrypted = Base 64_encode (mcrypt_encrypt (MCRYPT_RIJNDAEL_256, MD5 ($ key), $ x, MCRYPT_MODE_CBC, MD5 (MD5 ($ key))); $ Encrypted return; } Function decryption ($ y) {$ key = 'SuperSecretKey'; $ Decrypted = rtrim (mcrypt_decrypt (MCRYPT_RIJNDAEL_256, MD5 ($ key), base64_decode ($ y), MCRYPT_MODE_CBC, MD5 (MD5 ($ key)), "\ 0"); Return $ decrypted; }    

No comments:

Post a Comment