Dcrypt\Aes::decrypt PHP Method

decrypt() public static method

Decrypt cyphertext
public static decrypt ( string $cyphertext, string $password, integer $cost ) : string
$cyphertext string Cyphertext to decrypt
$password string Password that should be used to decrypt input data
$cost integer Number of HMAC iterations to perform on key
return string
    public static function decrypt($cyphertext, $password, $cost = 0)
    {
        // Find the IV at the beginning of the cypher text
        $iv = Str::substr($cyphertext, 0, self::IVSIZE);
        // Gather the checksum portion of the cypher text
        $chksum = Str::substr($cyphertext, self::IVSIZE, self::CKSIZE);
        // Gather message portion of cyphertext after iv and checksum
        $message = Str::substr($cyphertext, self::IVSIZE + self::CKSIZE);
        // Derive key from password
        $key = self::key($password, $iv, $cost, self::RIJNDA, self::mode());
        // Calculate verification checksum
        $verify = self::checksum($message, $iv, $key, self::RIJNDA, self::mode());
        // Verify HMAC before decrypting
        self::checksumVerify($verify, $chksum);
        // Decrypt message and return
        return \openssl_decrypt($message, static::CIPHER, $key, 1, $iv);
    }

Usage Example

Beispiel #1
0
 public function testVector()
 {
     $input = 'hello world';
     $pass = '******';
     $vector = \base64_decode('eZu2DqB2gYhdA2YkjagLNJJVMVo1BbpJ75tW/PO2bGIY98XHD+Gp+YlO5cv/rHzo45LHMCxL2qOircdST1w5hg==');
     $this->assertEquals($input, Aes::decrypt($vector, $pass));
 }
All Usage Examples Of Dcrypt\Aes::decrypt