Ejemplo n.º 1
0
 /**
  * Tests if example messages match actual messages after encryption/decryption and vice versa:
  * decrypt(encrypted_example) == unencrypted_example
  * encrypt(unencrypted_example) == encrypted_example
  *
  * @dataProvider filenameProvider
  */
 public function testMessageEncryptionAgainstFixture($filename)
 {
     $fixture = json_decode(file_get_contents($filename));
     foreach ($fixture->items as $example) {
         $cipherParams = Crypto::getDefaultParams(['key' => $fixture->key, 'algorithm' => $fixture->algorithm, 'keyLength' => $fixture->keylength, 'mode' => $fixture->mode, 'iv' => $fixture->iv, 'base64Key' => true, 'base64Iv' => true]);
         $decodedExample = new Message();
         $decodedExample->fromJSON($example->encoded);
         $decryptedExample = new Message();
         $decryptedExample->setCipherParams($cipherParams);
         $decryptedExample->fromJSON($example->encrypted);
         $this->assertEquals($decodedExample->data, $decryptedExample->data, 'Expected unencrypted and decrypted message\'s contents to match');
         $decodedExample->setCipherParams($cipherParams);
         $encryptedJSON = json_decode($decodedExample->toJSON());
         $this->assertEquals($example->encrypted->data, $encryptedJSON->data, 'Expected encrypted and example encrypted message\'s contents to match');
     }
 }