Phalcon\Test\Unit\SecurityTest::testSecurityComputeHMAC PHP Method

testSecurityComputeHMAC() public method

Tests the HMAC computation
Since: 2014-09-12
Author: Nikolaos Dimopoulos ([email protected])
    public function testSecurityComputeHMAC()
    {
        $this->specify('The HMAC computation values are not identical', function ($key) {
            $security = new Security();
            $data = [];
            for ($i = 1; $i < 256; ++$i) {
                $data[] = str_repeat('a', $i);
            }
            foreach ($data as $text) {
                expect($security->computeHmac($text, $key, 'md5'))->equals(hash_hmac('md5', $text, $key));
            }
        }, ['examples' => [[substr(md5('test', true), 0, strlen(md5('test', true)) / 2)], [md5('test', true)], [md5('test', true) . md5('test', true)]]]);
    }