PMA\libraries\plugins\auth\AuthenticationCookie::cookieDecrypt PHP Method

cookieDecrypt() public method

Decryption using openssl's AES or phpseclib's AES (phpseclib uses mcrypt when it is available)
public cookieDecrypt ( string $encdata, string $secret ) : string | boolean
$encdata string encrypted data
$secret string the secret
return string | boolean original data, false on error
    public function cookieDecrypt($encdata, $secret)
    {
        $data = json_decode($encdata, true);
        if (!is_array($data) || !isset($data['mac']) || !isset($data['iv']) || !isset($data['payload']) || !is_string($data['mac']) || !is_string($data['iv']) || !is_string($data['payload'])) {
            return false;
        }
        $mac_secret = $this->getMACSecret($secret);
        $aes_secret = $this->getAESSecret($secret);
        $newmac = hash_hmac('sha1', $data['iv'] . $data['payload'], $mac_secret);
        if (!hash_equals($data['mac'], $newmac)) {
            return false;
        }
        if (self::useOpenSSL()) {
            return openssl_decrypt($data['payload'], 'AES-128-CBC', $secret, 0, base64_decode($data['iv']));
        } else {
            $cipher = new Crypt\AES(Crypt\Base::MODE_CBC);
            $cipher->setIV(base64_decode($data['iv']));
            $cipher->setKey($aes_secret);
            return $cipher->decrypt(base64_decode($data['payload']));
        }
    }

Usage Example

 /**
  * Test for PMA\libraries\plugins\auth\AuthenticationConfig::cookieDecrypt
  *
  * @return void
  */
 public function testCookieDecrypt()
 {
     $this->object->setIV('testiv09testiv09');
     // works with the openssl extension active or inactive
     $this->assertEquals('data123', $this->object->cookieDecrypt('+coP/up/ZBTBwbiEpCUVXQ==', 'sec321'));
 }
All Usage Examples Of PMA\libraries\plugins\auth\AuthenticationCookie::cookieDecrypt