/** * Decrypts the attribute for setting/use in the interface. * @param string $name Attribute to be transformed * @return string */ public function unpackAttribute($name) { if ($this->getOwner()->{$name}) { return self::$encrypt ? self::$encryption->decrypt($this->getOwner()->{$name}) : $this->getOwner()->{$name}; } else { return null; } }
public function testFileSaving() { $this->setupTestDirs(); $bd = $this->baseDir; $keyFile = "{$bd}/{$this->relFileList[0]}"; $IVFile = "{$bd}/{$this->relFileList[1]}"; // Remove them to test that they get properly created: unlink($keyFile); unlink($IVFile); $enc = new EncryptUtil($keyFile, $IVFile, true); // Generate/save new key & IV into files. $enc->saveNew(); // Test that files got created: $this->assertFileExists($keyFile); $this->assertFileExists($IVFile); // Now encrypt a value with this instance: $expected = $this->junkToEncrypt; $encrypted = $enc->encrypt($expected); // ...Then try creating a new instance, and testing that the values // between instantiations are constistent $enc = new EncryptUtil($keyFile, $IVFile, true); $this->assertEquals($expected, $enc->decrypt($encrypted), 'Failed asserting the encryption key and IV were properly saved and re-used.'); $this->removeTestDirs(); }