Prado\Security\TSecurityManager::setEncryptionKey PHP 메소드

setEncryptionKey() 공개 메소드

public setEncryptionKey ( $value )
    public function setEncryptionKey($value)
    {
        if ('' === $value) {
            throw new TInvalidDataValueException('securitymanager_encryptionkey_invalid');
        }
        $this->_encryptionKey = $value;
    }

Usage Example

예제 #1
0
 public function testEncryptDecrypt()
 {
     $sec = new TSecurityManager();
     $sec->init(null);
     // loop through different string size
     $testText = md5('a text (not) full of entrophy');
     for ($i = 1; $i < strlen($testText); $i++) {
         $sec->setEncryptionKey('aKey');
         $plainText = substr($testText, 0, $i);
         try {
             $encrypted = $sec->encrypt($plainText);
         } catch (TNotSupportedException $e) {
             self::markTestSkipped('mcrypt extension not loaded');
             return;
         }
         $decrypted = $sec->decrypt($encrypted);
         // the decrypted string is padded with \0
         $decrypted = strstr($decrypted, "", TRUE);
         self::assertEquals($plainText, $decrypted);
         // try change key
         $sec->setEncryptionKey('anotherKey');
         self::assertNotEquals($plainText, $sec->decrypt($encrypted));
     }
 }