public function testNonAESEncryptionSupport() { $blowfishParams = Crypto::getDefaultParams(['key' => Crypto::generateRandomKey(128), 'algorithm' => 'bf', 'mode' => 'ecb']); $encrypted = Crypto::encrypt('test', $blowfishParams); $decrypted = Crypto::decrypt($encrypted, $blowfishParams); $this->assertNotEquals($encrypted, $decrypted); $this->assertEquals('test', $decrypted); try { Crypto::getDefaultParams(['key' => Crypto::generateRandomKey(), 'algorithm' => 'fake']); } catch (\Exception $ex) { $this->assertInstanceOf('Ably\\Exceptions\\AblyException', $ex, 'Expected to raise an exception on unknown encryption mode'); } }
/** * Check if message encodings are correct, including the default encryption */ public function testMessageEncodings() { $msg = new Message(); $msg->data = 'This is a UTF-8 string message payload. äôč ビール'; $this->assertEquals('', $this->getMessageEncoding($msg), 'Expected empty message encoding'); $msg->data = (object) ['test' => 'This is a JSONObject message payload']; $this->assertEquals('json', $this->getMessageEncoding($msg), 'Expected empty message encoding'); $msg->data = hex2bin('00102030405060708090a0b0c0d0e0f0ff'); $this->assertEquals('base64', $this->getMessageEncoding($msg), 'Expected empty message encoding'); $msg->setCipherParams(Crypto::getDefaultParams(['key' => Crypto::generateRandomKey(128)])); $msg->data = 'This is a UTF-8 string message payload. äôč ビール'; $this->assertEquals('utf-8/cipher+aes-128-cbc/base64', $this->getMessageEncoding($msg), 'Expected empty message encoding'); $msg->data = (object) ['test' => 'This is a JSONObject message payload']; $this->assertEquals('json/utf-8/cipher+aes-128-cbc/base64', $this->getMessageEncoding($msg), 'Expected empty message encoding'); $msg->data = hex2bin('00102030405060708090a0b0c0d0e0f0ff'); $this->assertEquals('cipher+aes-128-cbc/base64', $this->getMessageEncoding($msg), 'Expected empty message encoding'); }