2

这是我的代码:

class Security  {

    public function __construct($textkey) {
        $this->securekey = hash('sha256',$textkey,TRUE);
        $this->iv = mcrypt_create_iv(32);
    }

    // holds properties for encrpyting  
    private $securekey, $iv;

    /*
     * encrypting data 
     *
     * @param $data the value to be encrypted 
     * @return string the encrypted data 
     */
    public function encryptUrlData($input) {
        $url = base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $this->securekey, $input, MCRYPT_MODE_ECB, $this->iv));
        return urlencode($url);
    }

    /*
     * encrypting data 
     *
     * @param $data the value to be encrypted 
     * @return string the encrypted data 
     */
    public function decryptUrlData($input) {
        $input = urldecode($input);
        return trim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $this->securekey, base64_decode($input), MCRYPT_MODE_ECB, $this->iv));
    }

我正在加密 id,所以基本上我加密的值只是数字。例如:值为“3”的id将被成功解密,而“1”则未被成功解密。

4

0 回答 0