예제 #1
0
 public function testEncryptByPassword()
 {
     $data = 'known data';
     $key = 'secret';
     $encryptedData = $this->security->encryptByPassword($data, $key);
     $this->assertFalse($data === $encryptedData);
     $decryptedData = $this->security->decryptByPassword($encryptedData, $key);
     $this->assertEquals($data, $decryptedData);
     $tampered = $encryptedData;
     $tampered[20] = ~$tampered[20];
     $decryptedData = $this->security->decryptByPassword($tampered, $key);
     $this->assertTrue(false === $decryptedData);
 }
예제 #2
0
파일: SecurityTest.php 프로젝트: nxnx/yii2
 /**
  * @dataProvider dataProviderEncryptByPasswordCompat
  *
  * @param string $password encryption password
  * @param string $data plaintext hex string
  * @param string $encrypted ciphertext hex string
  */
 public function testEncryptByPasswordCompat($password, $data, $encrypted)
 {
     $data = hex2bin(preg_replace('{\\s+}', '', $data));
     $encrypted = hex2bin(preg_replace('{\\s+}', '', $encrypted));
     $this->assertEquals($data, $this->security->decryptByPassword($encrypted, $password));
 }