Phalcon\Test\Unit\CryptTest::testCryptEncryption PHP Метод

testCryptEncryption() публичный Метод

Tests the encryption
С версии: 2014-10-17
Автор: Nikolaos Dimopoulos ([email protected])
public testCryptEncryption ( )
    public function testCryptEncryption()
    {
        $this->specify("encryption does not return correct results", function () {
            $tests = [md5(uniqid()) => str_repeat('x', mt_rand(1, 255)), time() . time() => str_shuffle('abcdefeghijklmnopqrst'), 'le$ki12432543543543543' => null];
            $ciphers = ['AES-128-ECB', 'AES-128-CBC', 'AES-128-CFB', 'AES-128-OFB'];
            $crypt = new Crypt();
            foreach ($ciphers as $cipher) {
                $crypt->setCipher($cipher);
                foreach ($tests as $key => $test) {
                    $crypt->setKey(substr($key, 0, 16));
                    $encryption = $crypt->encrypt($test);
                    $actual = rtrim($crypt->decrypt($encryption), "");
                    expect($actual)->equals($test);
                }
                foreach ($tests as $key => $test) {
                    $encryption = $crypt->encrypt($test, substr($key, 0, 16));
                    $actual = rtrim($crypt->decrypt($encryption, substr($key, 0, 16)), "");
                    expect($actual)->equals($test);
                }
            }
        });
    }