How to encrypt/decrypt data in php?

前端 未结 6 778
北恋
北恋 2020-11-22 07:17

I\'m currently a student and I\'m studying PHP, I\'m trying to make a simple encrypt/decrypt of data in PHP. I made some online research and some of them were quite confusin

6条回答
  •  孤街浪徒
    2020-11-22 07:21

    I'm think this has been answered before...but anyway, if you want to encrypt/decrypt data, you can't use SHA256

    //Key
    $key = 'SuperSecretKey';
    
    //To Encrypt:
    $encrypted = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, 'I want to encrypt this', MCRYPT_MODE_ECB);
    
    //To Decrypt:
    $decrypted = mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key, $encrypted, MCRYPT_MODE_ECB);
    

提交回复
热议问题