@@ -109,6 +109,7 @@ public function validateHashDataProvider()
109
109
* @param mixed $key
110
110
*
111
111
* @dataProvider encryptWithEmptyKeyDataProvider
112
+ * @expectedException \SodiumException
112
113
*/
113
114
public function testEncryptWithEmptyKey ($ key )
114
115
{
@@ -161,8 +162,14 @@ public function testEncrypt()
161
162
$ data = 'Mares eat oats and does eat oats, but little lambs eat ivy. ' ;
162
163
163
164
$ actual = $ this ->_model ->encrypt ($ data );
165
+
166
+ // Extract the initialization vector and encrypted data
167
+ $ parts = explode (': ' , $ actual , 3 );
168
+ list (, , $ encryptedData ) = $ parts ;
169
+
170
+ $ crypt = new SodiumChachaIetf (self ::CRYPT_KEY_1 );
164
171
// Verify decrypted matches original data
165
- $ this ->assertEquals ($ data , $ this -> _model -> decrypt ($ actual ));
172
+ $ this ->assertEquals ($ data , $ crypt -> decrypt (base64_decode (( string ) $ encryptedData ) ));
166
173
}
167
174
168
175
public function testDecrypt ()
@@ -186,7 +193,7 @@ public function testLegacyDecrypt()
186
193
list (, , $ iv , $ encrypted ) = $ parts ;
187
194
188
195
// Decrypt returned data with RIJNDAEL_256 cipher, cbc mode
189
- $ crypt = new Crypt (self ::CRYPT_KEY_1 , MCRYPT_RIJNDAEL_256 , MCRYPT_MODE_ECB , $ iv );
196
+ $ crypt = new Crypt (self ::CRYPT_KEY_1 , MCRYPT_RIJNDAEL_256 , MCRYPT_MODE_CBC , $ iv );
190
197
// Verify decrypted matches original data
191
198
$ this ->assertEquals ($ encrypted , base64_encode ($ crypt ->encrypt ($ actual )));
192
199
}
@@ -217,7 +224,7 @@ public function testEncryptDecryptNewKeyAdded()
217
224
218
225
public function testValidateKey ()
219
226
{
220
- $ this ->assertNull ( $ this -> _model ->validateKey (self ::CRYPT_KEY_1 ) );
227
+ $ this ->_model ->validateKey (self ::CRYPT_KEY_1 );
221
228
}
222
229
223
230
/**
@@ -259,3 +266,4 @@ public function testGetHashMustUseSpecifiedHashingAlgo($password, $salt, $hashAl
259
266
$ this ->assertEquals ($ expected , $ hash );
260
267
}
261
268
}
269
+
0 commit comments