Pop\Crypt\Mcrypt::create PHP Method

create() public method

Method to create the hashed value
public create ( string $string ) : string
$string string
return string
    public function create($string)
    {
        $hash = null;
        $this->ivSize = mcrypt_get_iv_size($this->cipher, $this->mode);
        $this->salt = null === $this->salt ? substr(str_replace('+', '.', base64_encode(String::random(32))), 0, $this->ivSize) : substr(str_replace('+', '.', base64_encode($this->salt)), 0, $this->ivSize);
        $this->iv = mcrypt_create_iv($this->ivSize, $this->source);
        $hash = mcrypt_encrypt($this->cipher, $this->salt, $string, $this->mode, $this->iv);
        $hash = base64_encode($this->iv . $this->salt . '$' . $hash);
        return $hash;
    }

Usage Example

示例#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::create