Odyssey
bankingHcuConnectTest.php
1 <?php
2 
3 use PHPUnit\Framework\TestCase;
4 
5 require_once 'SSOEncryption.i';
6 
7 class HcuConnectTest extends TestCase {
8  function setUp() {
9  $this->Cu = "SCRUBCU";
10  $this->key = substr(hash("md5", $this->Cu.":testkeysuffix"), 0, 24);
11  $this->key_pub = substr(hash("md5", $this->Cu.":testkeypub"), 0, 24);
12  $this->common_cbc_iv = base64_decode("QvkbnYUwcyw=");
13  }
14 
15  function test_3des_cbc_ticket_chkfree() {
16  $digeststr = "ts=yyyy&ss=xxxx&pw=pwdpwd}";
17  $digest = base64_encode(sha1("$digeststr", true));
18  $ticket = "$digeststr&dg=$digest";
19 
20  list($enc_openssl,
21  $ticket_padded_openssl) = encrypt_ticket_openssl($ticket,
22  $this->key,
23  $this->common_cbc_iv);
24 
25  $dec_openssl = decrypt_ticket_openssl($enc_openssl,
26  $this->key,
27  $this->common_cbc_iv);
28 
29  $this->assertEquals($dec_openssl, $ticket_padded_openssl);
30 
31  if (function_exists("mdecrypt_generic") && function_exists("mcrypt_generic")) {
32 
33  // encrypt padded string with mcrypt
34  list($enc_mcrypt,
35  $ticket_padded_mcrypt) = encrypt_ticket_mcrypt($ticket,
36  $this->key,
37  $this->common_cbc_iv);
38  // decrypt with mcrypt
39  $dec_mcrypt = decrypt_ticket_mcrypt($enc_mcrypt,
40  $this->key,
41  $this->common_cbc_iv);
42  $this->assertEquals($dec_mcrypt, $ticket_padded_mcrypt);
43 
44  // assert openssl and mcrypt generate same ciphertext
45  $this->assertEquals($enc_openssl, $enc_mcrypt);
46 
47  // assert openssl and mcrypt used same padded string
48  $this->assertEquals($ticket_padded_openssl, $ticket_padded_mcrypt);
49 
50  // decrypt the mcrypt encrypted content using the same encryption
51  // mode, and assert with the original padded string
52  $enc_mcrypt_dec_openssl = decrypt_ticket_openssl($enc_mcrypt,
53  $this->key,
54  $this->common_cbc_iv);
55  $this->assertEquals($enc_mcrypt_dec_openssl, $ticket_padded_mcrypt);
56  }
57  }
58 
59  function test_3des_cbc_ezcard_sso() {
60  // encryption and decryption compatibility test
61  // does not use the actual keys and IVs
62  $clientId = "12345";
63  $sv0 = substr('00000000' . strval(rand(1, 99999999)), -8);
64  $card4="4567";
65  $cardsig="68iq1Lg3DZeJsvXtyryOkJEVuAgOp2CxDnu9YgTcaQax";
66  $cardtype="P";
67  $Ml="someone@sampleuser.com";
68  $edate="11/13/2009 20:00:00";
69  $salt = 'KLxK-We8';
70 
71  $sso_request = "<SSORequest AcctLast4=\"$card4\" AcctSignature=\"$cardsig\" CardType=\"$cardtype\" EmailAddress=\"$Ml\" ExpireDateTime=\"$edate\" sv0=\"$sv0\" />";
72  $priviv = $this->common_cbc_iv;
73 
74  // OPENSSL based tests
75  list($sso_request_openssl,
76  $enc_inner_openssl,
77  $sso_wrap_openssl,
78  $enc_outer_openssl) = encrypt_ezcard_sso($sso_request,
79  $clientId,
80  $this->key,
81  $this->key_pub,
82  $priviv,
83  $salt);
84 
85  $dec_openssl_outer = decrypt_ezcard_openssl($enc_outer_openssl,
86  $this->key_pub,
87  $priviv);
88  $this->assertEquals($dec_openssl_outer, $sso_wrap_openssl);
89 
90  $dec_openssl_inner = decrypt_ezcard_openssl($enc_inner_openssl,
91  $this->key,
92  $priviv);
93  $this->assertEquals($dec_openssl_inner, $sso_request_openssl);
94 
95  // MCRYPT based test
96  if (function_exists("mdecrypt_generic") && function_exists("mcrypt_generic")) {
97 
98  // encrypt inner and outer packet with mcrypt
99  list($sso_request_mcrypt,
100  $enc_inner,
101  $sso_wrap_mcrypt,
102  $enc_out) = encrypt_ezcard_sso_mcrypt($sso_request,
103  $clientId,
104  $this->key,
105  $this->key_pub,
106  $priviv,
107  $salt);
108 
109  // decrypt outer packet with mcrypt
110  $dec_mcrypt_outer = decrypt_ezcard_mcrypt($enc_out,
111  $this->key_pub,
112  $priviv);
113  $this->assertEquals($dec_mcrypt_outer, $sso_wrap_mcrypt);
114 
115 
116  // assert mcrypt and openssl generated same outer packet ciphertext
117  $this->assertEquals($enc_out, $enc_outer_openssl);
118 
119  // assert mcrypt and openssl use same padded outer packet string
120  $this->assertEquals($sso_wrap_mcrypt, $sso_wrap_openssl);
121 
122  // decrypt mcrypt encrypted outer packet with openssl
123  $enc_mcrypt_dec_openssl_out = decrypt_ezcard_openssl($enc_out,
124  $this->key_pub,
125  $priviv);
126  $this->assertEquals($enc_mcrypt_dec_openssl_out, $sso_wrap_mcrypt);
127 
128 
129  // decrypt inner packet with mcrypt
130  $dec_mcrypt_inner = decrypt_ezcard_mcrypt($enc_inner,
131  $this->key,
132  $priviv);
133  $this->assertEquals($dec_mcrypt_inner, $sso_request_mcrypt);
134 
135  // assert mcrypt and openssl generated same inner packet ciphertext
136  $this->assertEquals($enc_inner, $enc_inner_openssl);
137 
138  // assert mcrypt and openssl use same padded inner packet string
139  $this->assertEquals($sso_request_mcrypt, $sso_request_openssl);
140 
141  // decrypt mcrypt encrypted inner packet with openssl
142  $enc_mcrypt_dec_openssl_inner = decrypt_ezcard_openssl($enc_inner,
143  $this->key,
144  $priviv);
145  $this->assertEquals($enc_mcrypt_dec_openssl_inner, $sso_request_mcrypt);
146  }
147  }
148 
149  function test_3des_cbc_ezcard_sso_2() {
150  // Actual data received from logging for FIS_EZCARD
151  // Uses the actual keys and IVs
152  $clientId = "052514";
153  $salt = "-1sOztns";
154 
155  $card4="0602";
156  $cardsig="807vbxwWV9OveEbYK758phggvHWLWarl_wpGXhKodZK3";
157  $cardtype="P";
158  $Ml="anamagana13@yahoo.com";
159  $edate="03/25/19 20:50:40";
160 
161  $sso_request = "<SSORequest AcctLast4=\"${card4}\" AcctSignature=\"${cardsig}\" CardType=\"${cardtype}\" EmailAddress=\"${Ml}\" ExpireDateTime=\"${edate}\" />";
162 
163  $expected_inner_enc = "5TLwHzkpv1kM4rvZjdegjEmXXKo0rOmJWgXEkkoR-002zQ5-5zuPeA96hmABKG5lhvMRga7f2J5oPZTB6Gsxxon8z8CY2gxFZHDpr-JrS0cWRe1RYH_wPkmxCuRufkmCPnoIGy_mNWkHtzeEYTVvUJ7EWI2uG4K70f98VCuHZZ1rmnNMdL492MFjCDnqoVWRYNbx6x5eAm-Cfe_S3rPdcwrmZiKJjsHbPUQLMZC_P3HdZGYlKgY68A..";
164 
165  $expected_wrap_enc = "xzzw8hA0oqkvwcEXncNI4gTzhbkMfMb4MWkRDH_7TnqifWxEjAYmcKMSD5-lCMRrqHc5Bqp4sKWjZ1rEOmKRg-BS3mT7-ciLsaEpsEEqXvvXcuOSPz4mbARQmWLm2M4YFLrxkevsbQT2Rgu56tocLnC2WjGZg79EYZGBzMxomVclstKrfImIl76Gf5vxnxcKDhFqxGZujX3C45FHASjuDUEPns-eElR278R3aPAp3mFHP2RGCmqs_mfi_r7KPyLdwMss6BhjXIWKq5mLD_z488cBBRXsCP-tuZ_G4BSBAFFoNZDqjDO6dnEbtN2TBXwydK-WS98eSYD1IysXpfhGrnV8gWVKttCQhU6dstsbTru6r2asUAXdZQUiNYSbyxn1tsZunPQU5rKAbuAfvd307kpNS3MhNfws";
166  $priviv = hex2bin("000000000000000000000000");
167  $ezkey_pub = hex2bin("BDA30F6A4DEAFDFA8ACEB0931D0A5BC2777F49EE27AE32B4");
168  $ezkey_priv = hex2bin("F495840A66DCC85FF61F9C0C65CDBB38BC62E10AF51FCE78");
169 
170  // OPENSSL based tests
171  list($sso_request_openssl,
172  $enc_inner_openssl,
173  $sso_wrap_openssl,
174  $enc_outer_openssl) = encrypt_ezcard_sso($sso_request,
175  $clientId,
176  $ezkey_priv,
177  $ezkey_pub,
178  $priviv,
179  $salt);
180 
181  // decrypt outer packet with openssl
182  $dec_openssl_outer = decrypt_ezcard_openssl($enc_outer_openssl,
183  $ezkey_pub,
184  $priviv);
185  $this->assertEquals($dec_openssl_outer, $sso_wrap_openssl);
186 
187  // decrypt inner packet with openssl
188  $dec_openssl_inner = decrypt_ezcard_openssl($enc_inner_openssl,
189  $ezkey_priv,
190  $priviv);
191  $this->assertEquals($dec_openssl_inner, $sso_request_openssl);
192 
193  // verify both the inner and outer packet ciphertext are correct for openssl
194  $this->assertEquals($enc_outer_openssl, $expected_wrap_enc);
195  $this->assertEquals($enc_inner_openssl, $expected_inner_enc);
196 
197  // MCRYPT based test
198  if (function_exists("mdecrypt_generic") && function_exists("mcrypt_generic")) {
199 
200  // encrypt inner and outer packet with mcrypt
201  list($sso_request_mcrypt,
202  $enc_inner,
203  $sso_wrap_mcrypt,
204  $enc_out) = encrypt_ezcard_sso_mcrypt($sso_request,
205  $clientId,
206  $ezkey_priv,
207  $ezkey_pub,
208  $priviv,
209  $salt);
210 
211  // verify both the inner and outer packet ciphertext
212  // are correct for mcrypt
213  $this->assertEquals($enc_out, $expected_wrap_enc);
214  $this->assertEquals($enc_inner, $expected_inner_enc);
215 
216  // decrypt outer packet with mcrypt
217  $dec_mcrypt_outer = decrypt_ezcard_mcrypt($enc_out,
218  $ezkey_pub,
219  $priviv);
220  $this->assertEquals($dec_mcrypt_outer, $sso_wrap_mcrypt);
221 
222 
223  // assert mcrypt and openssl generated same outer packet ciphertext
224  $this->assertEquals($enc_out, $enc_outer_openssl);
225 
226  // assert mcrypt and openssl use same padded outer packet string
227  $this->assertEquals($sso_wrap_mcrypt, $sso_wrap_openssl);
228 
229  // decrypt mcrypt encrypted outer packet with openssl
230  $enc_mcrypt_dec_openssl_out = decrypt_ezcard_openssl($enc_out,
231  $ezkey_pub,
232  $priviv);
233  $this->assertEquals($enc_mcrypt_dec_openssl_out, $sso_wrap_mcrypt);
234 
235  // decrypt inner packet with mcrypt
236  $dec_mcrypt_inner = decrypt_ezcard_mcrypt($enc_inner,
237  $ezkey_priv,
238  $priviv);
239 
240  $this->assertEquals($dec_mcrypt_inner, $sso_request_mcrypt);
241 
242  // assert mcrypt and openssl generated same inner packet ciphertext
243  $this->assertEquals($enc_inner, $enc_inner_openssl);
244 
245  // assert mcrypt and openssl use same padded inner packet string
246  $this->assertEquals($sso_request_mcrypt, $sso_request_openssl);
247 
248  // decrypt mcrypt encrypted inner packet with openssl
249  $enc_mcrypt_dec_openssl_inner = decrypt_ezcard_openssl($enc_inner,
250  $ezkey_priv,
251  $priviv);
252  $this->assertEquals($enc_mcrypt_dec_openssl_inner, $sso_request_mcrypt);
253  }
254  }
255 
256  function test_3des_ecb_certegy() {
257  $showurl=1;
258  $FIID="8000"; #CU Institution ID for testing
259  // $ACCOUNT="214027153"; # not enrolled
260  $ACCOUNT="210328770001"; # enrolled";
261 
262  // OPENSSL test
263  // encrypt openssl
264  list($account_enc_openssl,
265  $account_padded_openssl) = encrypt_certegy_openssl($ACCOUNT,
266  $this->key);
267 
268  // decrypt openssl
269  $account_dec_openssl = decrypt_certegy_openssl($account_enc_openssl, $this->key);
270  $this->assertEquals($account_padded_openssl, $account_dec_openssl);
271 
272  // MCRYPT test
273  if (function_exists("mdecrypt_generic") && function_exists("mcrypt_generic")) {
274  // encrypt with mcrypt
275  list($account_enc_mcrypt, $account_padded) = encrypt_certegy_account_mcrypt($ACCOUNT,
276  $this->key);
277 
278  // assert mcrypt and openssl generate same ciphertext
279  $this->assertEquals($account_enc_openssl, $account_enc_mcrypt);
280 
281  // assert mcrypt and openssl use same padded string before encryption
282  $this->assertequals($account_padded_openssl, $account_padded);
283 
284  // decrypt mcrypt encrypted cipher using openssl
285  $account_enc_mcrypt_dec_openssl = decrypt_certegy_openssl($account_enc_mcrypt,
286  $this->key);
287  $this->assertEquals($account_padded, $account_enc_mcrypt_dec_openssl);
288 
289  // decrypt with mcrypt
290  $account_dec_mcrypt = decrypt_certegy_account_mcrypt($account_enc_mcrypt, $this->key);
291  $this->assertequals($account_padded, $account_dec_mcrypt);
292  }
293  }
294 
295  function test_3des_ecb_digital() {
296  # values for testing
297  $CustID="103"; #static string assigned by DigitalMailer
298  $ACCOUNT="88888888";
299  $servicepass="thisisatest";
300  $servicekey="52g2jajrt56syh5j2yf82ngf";
301  $showurl=1; # look before we leap
302  $currdate = gmdate('YmdHi'); # using GMT
303  $GMT = 1;
304 
305  $srcstring = "ACCOUNT={$ACCOUNT}&TIMESTAMP={$currdate}&CID={$CustID}&PASS={$servicepass}&GMT={$GMT}";
306 
307  // OPENSSL test
308  // encrypt openssl
309  list($digital_enc_openssl,
310  $srcstring_padded_openssl) = encrypt_digital_openssl($srcstring,
311  $servicekey);
312 
313  // // decrypt openssl
314  $digital_dec_openssl = decrypt_digital_openssl($digital_enc_openssl, $servicekey);
315  $this->assertEquals($srcstring_padded_openssl, $digital_dec_openssl);
316 
317  // MCRYPT test
318  if (function_exists("mdecrypt_generic") && function_exists("mcrypt_generic")) {
319  // encrypt with mcrypt
320  list($digital_enc_mcrypt,
321  $srcstring_padded) = encrypt_digital_mcrypt($srcstring,
322  $servicekey);
323 
324  // assert mcrypt and openssl generate the same ciphertext
325  $this->assertEquals($digital_enc_openssl, $digital_enc_mcrypt);
326 
327  // assert mcrypt and openssl encrypt same padded string
328  $this->assertEquals($srcstring_padded_openssl, $srcstring_padded);
329 
330  // decrypt mcrypt encrypted cipher using openssl
331  $digital_enc_mcrypt_dec_openssl = decrypt_digital_openssl($digital_enc_mcrypt,
332  $servicekey);
333  $this->assertEquals($srcstring_padded, $digital_enc_mcrypt_dec_openssl);
334 
335  // decrypt with mcrypt
336  $digital_dec_mcrypt = decrypt_digital_mcrypt($digital_enc_mcrypt, $servicekey);
337  $this->assertequals($srcstring_padded, $digital_dec_mcrypt);
338  }
339 
340  }
341 
342  function test_3des_ecb_digital_2() {
343  // values for testing, actual values from
344  // the specification documentation
345  $CustID="103"; #static string assigned by DigitalMailer
346  $ACCOUNT="1231234";
347  $servicepass="1test1";
348  $servicekey="123456781234567812345678";
349  $showurl="1"; # look before we leap
350  $currdate = "200304210915"; # using GMT
351  $GMT = 1;
352 
353  // last 16 bits are for padded characters
354  $expected_enc_with_pads = hex2bin("e553273afd34f4b2fb7c430b0ace9d63b07cb006b2748dbb14091ffe808bf524bae218b3c06ce9fde1fb974e6a695842cdb63fdd92f837de1c569468ee764f7efeb959b7d4642fcb");
355 
356  $srcstring = "CID={$CustID}&ACCOUNT={$ACCOUNT}&PASS={$servicepass}&TIMESTAMP={$currdate}&GMT={$GMT}";
357 
358  // OPENSSL test
359  // encrypt openssl
360  list($digital_enc_openssl,
361  $srcstring_padded_openssl) = encrypt_digital_openssl($srcstring,
362  $servicekey);
363 
364  // verify generated ciphertext
365  $this->assertEquals($digital_enc_openssl, $expected_enc_with_pads);
366 
367  // decrypt openssl
368  $digital_dec_openssl = decrypt_digital_openssl($digital_enc_openssl, $servicekey);
369  $this->assertEquals($srcstring_padded_openssl, $digital_dec_openssl);
370 
371  // // MCRYPT test
372  if (function_exists("mdecrypt_generic") && function_exists("mcrypt_generic")) {
373  // encrypt with mcrypt
374  list($digital_enc_mcrypt,
375  $srcstring_padded) = encrypt_digital_mcrypt($srcstring,
376  $servicekey);
377 
378  // verify generated ciphertext
379  $this->assertEquals($digital_enc_mcrypt, $expected_enc_with_pads);
380 
381  // assert mcrypt and openssl generate the same ciphertext
382  $this->assertEquals($digital_enc_openssl, $digital_enc_mcrypt);
383 
384  // assert mcrypt and openssl encrypt same padded string
385  $this->assertEquals($srcstring_padded_openssl, $srcstring_padded);
386 
387  // decrypt mcrypt encrypted cipher using openssl
388  $digital_enc_mcrypt_dec_openssl = decrypt_digital_openssl($digital_enc_mcrypt,
389  $servicekey);
390  $this->assertEquals($srcstring_padded, $digital_enc_mcrypt_dec_openssl);
391 
392  // decrypt with mcrypt
393  $digital_dec_mcrypt = decrypt_digital_mcrypt($digital_enc_mcrypt, $servicekey);
394  $this->assertequals($srcstring_padded, $digital_dec_mcrypt);
395 
396  }
397 
398  }
399 
400  function test_cast5_ecb_billpay() {
401  # values for testing
402  $billpayid = "billpayid sample data";
403  $ipaykey = substr($this->key, 0, 16);
404 
405  // OPENSSL test
406  // encrypt openssl
407  list($billpayid_enc_openssl,
408  $billpayid_padded_openssl) = encrypt_billpay_openssl($billpayid,
409  $ipaykey);
410 
411  // decrypt openssl
412  $billpayid_dec_openssl = decrypt_billpay_openssl($billpayid_enc_openssl, $ipaykey);
413  $this->assertEquals($billpayid_padded_openssl, $billpayid_dec_openssl);
414 
415  // MCRYPT test
416  if (function_exists("mdecrypt_generic") && function_exists("mcrypt_generic")) {
417  // encrypt with mcrypt
418  list($billpayid_enc_mcrypt,
419  $billpayid_padded) = encrypt_billpay_mcrypt($billpayid,
420  $ipaykey);
421 
422  // assert that mcrypt and openssl generate the same encrypted string
423  $this->assertEquals($billpayid_enc_openssl, $billpayid_enc_mcrypt);
424 
425  // assert that mcrypt and openssl apply the same padding before encryption
426  $this->assertEquals($billpayid_padded_openssl, $billpayid_padded);
427 
428  // decrypt mcrypt encrypted cipher using openssl
429  $billpayid_enc_mcrypt_dec_openssl = decrypt_billpay_openssl($billpayid_enc_mcrypt,
430  $ipaykey);
431  $this->assertEquals($billpayid_padded, $billpayid_enc_mcrypt_dec_openssl);
432 
433  // decrypt with mcrypt
434  $billpayid_dec_mcrypt = decrypt_billpay_mcrypt($billpayid_enc_mcrypt,
435  $ipaykey);
436  $this->assertequals($billpayid_padded, $billpayid_dec_mcrypt);
437  }
438 
439  }
440 
441  function test_aes_256_ecb_vsoft() {
442  # values for testing
443  $vsoftquery = "vsoft query sample data";
444  $vsoftkey = hash_hmac('md5', "somedata", "somekey");// 128bit key
445 
446 
447  // OPENSSL test
448  // encrypt openssl
449  list($vsoft_enc_openssl,
450  $vsoftquery_padded_openssl) = encrypt_vsoftquery_openssl($vsoftquery,
451  $vsoftkey);
452 
453  // // decrypt openssl
454  $vsoft_dec_openssl = decrypt_vsoftquery_openssl($vsoft_enc_openssl, $vsoftkey);
455  $this->assertEquals($vsoftquery_padded_openssl, $vsoft_dec_openssl);
456 
457  // MCRYPT test
458  if (function_exists("mdecrypt_generic") && function_exists("mcrypt_generic")) {
459  // encrypt with mcrypt
460  list($vsoft_enc_mcrypt,
461  $vsoftquery_padded) = encrypt_vsoftquery_mcrypt($vsoftquery,
462  $vsoftkey);
463 
464  // decrypt mcrypt encrypted cipher using openssl
465  $vsoft_enc_mcrypt_dec_openssl = decrypt_vsoftquery_openssl($vsoft_enc_mcrypt,
466  $vsoftkey);
467  $this->assertEquals($vsoftquery_padded, $vsoft_enc_mcrypt_dec_openssl);
468 
469  // assert openssl and mcrypt generated the same ciphertext
470  $this->assertEquals($vsoft_enc_openssl, $vsoft_enc_mcrypt);
471 
472  // assert openssl and mcrypt used the same padded string
473  $this->assertEquals($vsoftquery_padded, $vsoftquery_padded_openssl);
474 
475  // decrypt with mcrypt
476  $vsoft_dec_mcrypt = decrypt_vsoftquery_mcrypt($vsoft_enc_mcrypt,
477  $vsoftkey);
478  $this->assertequals($vsoftquery_padded, $vsoft_dec_mcrypt);
479  }
480 
481  }
482 
483  function test_hex2bin() {
484  $this->assertEquals(hex2bin("613553673455396d31314d773274495a"), "a5Sg4U9m11Mw2tIZ");
485  $this->assertEquals(bin2hex("a5Sg4U9m11Mw2tIZ"), "613553673455396d31314d773274495a");
486  }
487 
488  function test_aes_256_cbc_mvi() {
489  // actual data from the specification document
490  $mvi_query = "2008-06-02 13:28:45,Statements,1234567,,06/01/2008,06/01/2008,0";
491  $ckhexkey = "BTikvHBatPdAtgT3317QIQqGFY25WpIz";
492  $iv_mvi = "a5Sg4U9m11Mw2tIZ";
493  $expected_encrypted_value_hex = "b97f3985245be1065604c5808cebaa2e15813bf938cfaa3c198fd464565c13ced7c91ac6b68326ce5ed5e81cb7de81ac36b1106392bd8303d2aedf2c26161a8a";
494  $expected_iv_hex = "613553673455396d31314d773274495a";
495 
496  // encrypt with openssl
497  $mvi_cipher_iv_openssl = encrypt_mvi_openssl($mvi_query, $ckhexkey, $iv=$iv_mvi);
498  $this->assertEquals($mvi_cipher_iv_openssl,
499  $expected_encrypted_value_hex.$expected_iv_hex);
500 
501  // decrypt with openssl
502  $mvi_dec_openssl = decrypt_mvi_openssl($mvi_cipher_iv_openssl,
503  $ckhexkey);
504  $this->assertEquals($mvi_dec_openssl, $mvi_query);
505 
506 
507  // MCRYPT test
508  if (function_exists("mdecrypt_generic") && function_exists("mcrypt_generic")) {
509  // encrypt with mcrypt
510  $mvi_cipher_iv_mcrypt = encrypt_mvi_mcrypt($mvi_query,
511  $ckhexkey,$iv=$iv_mvi);
512 
513  // assert mcrypt and openssl generated same ciphertext
514  $this->assertEquals($mvi_cipher_iv_mcrypt,
515  $expected_encrypted_value_hex.$expected_iv_hex);
516  $this->assertEquals($mvi_cipher_iv_mcrypt, $mvi_cipher_iv_openssl);
517 
518 
519  // decrypt mcrypt encrypted ciphertext with openssl
520  $mvi_enc_mcrypt_dec_openssl = decrypt_mvi_openssl($mvi_cipher_iv_mcrypt,
521  $ckhexkey);
522  $this->assertEquals($mvi_query, $mvi_enc_mcrypt_dec_openssl);
523 
524 
525  // decrypt with mcrypt
526  $mvi_dec_mcrypt = decrypt_mvi_mcrypt($mvi_cipher_iv_mcrypt,
527  $ckhexkey);
528  $this->assertEquals($mvi_query, $mvi_dec_mcrypt);
529  }
530  }
531 
532  function test_aes_256_cbc_mvi_2() {
533  // actual data taken from the logs
534  $mvi_query = "2019-03-25 21:01:20,Checks,1000453728,4930,03/20/2019,03/20/2019,1";
535 
536  $ckhexkey = "lPVWJFs1F81j3nSkEIxFQqAI1Cu6YLrU";
537  $expected_encrypted_value_hex = "78d4fa151d1bed1a07b68c817172a28a1211a82deec74a5411be558f5645201085e27588e8ccb9943d8ee3fa4e263981eb2dddf788eb83be8ab32c2932426d267ebd7adb87dbb918143843135cf6ca57";
538  // inferred from the last 32 hexits of the expected encrypted hex value
539  $expected_iv_hex = "a39235682bb1fbf9ae753f92624fe086";
540  $iv_mvi = hex2bin("a39235682bb1fbf9ae753f92624fe086");
541 
542 
543  // encrypt with openssl
544  $mvi_cipher_iv_openssl = encrypt_mvi_openssl($mvi_query, $ckhexkey, $iv=$iv_mvi);
545  $this->assertEquals($mvi_cipher_iv_openssl,
546  $expected_encrypted_value_hex.$expected_iv_hex);
547 
548  // decrypt with openssl
549  $mvi_dec_openssl = decrypt_mvi_openssl($mvi_cipher_iv_openssl,
550  $ckhexkey);
551  $this->assertEquals($mvi_dec_openssl, $mvi_query);
552 
553 
554  // MCRYPT test
555  if (function_exists("mdecrypt_generic") && function_exists("mcrypt_generic")) {
556  // encrypt with mcrypt
557  $mvi_cipher_iv_mcrypt = encrypt_mvi_mcrypt($mvi_query,
558  $ckhexkey,$iv=$iv_mvi);
559 
560  // assert mcrypt and openssl generated same ciphertext
561  $this->assertEquals($mvi_cipher_iv_mcrypt,
562  $expected_encrypted_value_hex.$expected_iv_hex);
563  $this->assertEquals($mvi_cipher_iv_mcrypt, $mvi_cipher_iv_openssl);
564 
565 
566  // decrypt mcrypt encrypted ciphertext with openssl
567  $mvi_enc_mcrypt_dec_openssl = decrypt_mvi_openssl($mvi_cipher_iv_mcrypt,
568  $ckhexkey);
569  $this->assertEquals($mvi_query, $mvi_enc_mcrypt_dec_openssl);
570 
571 
572  // decrypt with mcrypt
573  $mvi_dec_mcrypt = decrypt_mvi_mcrypt($mvi_cipher_iv_mcrypt,
574  $ckhexkey);
575  $this->assertEquals($mvi_query, $mvi_dec_mcrypt);
576  }
577  }
578 
579  function tearDown() {
580 
581  }
582 }
583 
584 
585 ?>