Simplest two-way encryption using PHP

前端 未结 6 1712
半阙折子戏
半阙折子戏 2020-11-22 07:11

What is the simplest way of doing two way encryption in common PHP installs?

I need to be able to encrypt data with a string key, and use the same key to decrypt on

6条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-22 07:26

    IMPORTANT this answer is valid only for PHP 5, in PHP 7 use built-in cryptographic functions.

    Here is simple but secure enough implementation:

    • AES-256 encryption in CBC mode
    • PBKDF2 to create encryption key out of plain-text password
    • HMAC to authenticate the encrypted message.

    Code and examples are here: https://stackoverflow.com/a/19445173/1387163

提交回复
热议问题