Pop\Crypt\Mcrypt::decrypt PHP Method

decrypt() public method

Method to decrypt the hashed value
public decrypt ( string $hash ) : string
$hash string
return string
    public function decrypt($hash)
    {
        if ($this->ivSize == 0) {
            $this->ivSize = mcrypt_get_iv_size($this->cipher, $this->mode);
        }
        $decrypted = base64_decode($hash);
        $this->iv = substr($decrypted, 0, $this->ivSize);
        if (null === $this->salt) {
            $this->salt = substr($decrypted, $this->ivSize);
            $this->salt = substr($this->salt, 0, strpos($this->salt, '$'));
        }
        $decrypted = substr($decrypted, $this->ivSize + strlen($this->salt) + 1);
        return trim(mcrypt_decrypt($this->cipher, $this->salt, $decrypted, $this->mode, $this->iv));
    }

Usage Example

Exemplo n.º 1
0
 public function testMcrypt()
 {
     $crypt = new Crypt\Mcrypt();
     $crypt->setSalt('Test Salt');
     $this->assertEquals('Test Salt', $crypt->getSalt());
     $this->assertEquals(MCRYPT_RIJNDAEL_256, $crypt->getCipher());
     $this->assertEquals(MCRYPT_MODE_CBC, $crypt->getMode());
     $this->assertEquals(MCRYPT_RAND, $crypt->getSource());
     $hash = $crypt->create('12password34');
     $this->assertTrue($crypt->verify('12password34', $hash));
     $this->assertNotNull($crypt->getIv());
     $this->assertNotNull($crypt->getIvSize());
     $this->assertEquals('12password34', $crypt->decrypt($hash));
 }
All Usage Examples Of Pop\Crypt\Mcrypt::decrypt