1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Yiisoft\Security\Tests; |
4
|
|
|
|
5
|
|
|
require_once __DIR__ . '/MockHelper.php'; |
6
|
|
|
|
7
|
|
|
use Yiisoft\Security\AuthenticationException; |
8
|
|
|
use Yiisoft\Security\Crypt; |
9
|
|
|
use Yiisoft\Security\MockHelper; |
10
|
|
|
|
11
|
|
|
class CryptTest extends TestCase |
12
|
|
|
{ |
13
|
|
|
protected function tearDown() |
14
|
|
|
{ |
15
|
|
|
MockHelper::resetMocks(); |
16
|
|
|
} |
17
|
|
|
|
18
|
|
|
private function getCrypt(): Crypt |
19
|
|
|
{ |
20
|
|
|
// speed up test running |
21
|
|
|
return (new Crypt())->withDerivationIterations(1000); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
public function testEncryptAndDecryptByPassword(): void |
25
|
|
|
{ |
26
|
|
|
$crypt = $this->getCrypt(); |
27
|
|
|
$data = 'known data'; |
28
|
|
|
$key = 'secret'; |
29
|
|
|
|
30
|
|
|
$encryptedData = $crypt->encryptByPassword($data, $key); |
31
|
|
|
$decryptedData = $crypt->decryptByPassword($encryptedData, $key); |
32
|
|
|
|
33
|
|
|
|
34
|
|
|
$this->assertNotSame($data, $encryptedData); |
35
|
|
|
$this->assertEquals($data, $decryptedData); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function testDecryptByPasswordShouldThrowExceptionForTamperedData(): void |
39
|
|
|
{ |
40
|
|
|
$crypt = $this->getCrypt(); |
41
|
|
|
$data = 'known data'; |
42
|
|
|
$key = 'secret'; |
43
|
|
|
|
44
|
|
|
$this->expectException(AuthenticationException::class); |
45
|
|
|
|
46
|
|
|
$encryptedData = $crypt->encryptByPassword($data, $key); |
47
|
|
|
$tampered = $encryptedData; |
48
|
|
|
$tampered[20] = ~$tampered[20]; |
49
|
|
|
$crypt->decryptByPassword($tampered, $key); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function testEncryptAndDecryptByKey(): void |
53
|
|
|
{ |
54
|
|
|
$crypt = $this->getCrypt(); |
55
|
|
|
$data = 'known data'; |
56
|
|
|
$key = random_bytes(80); |
57
|
|
|
|
58
|
|
|
$encryptedData = $crypt->encryptByKey($data, $key); |
59
|
|
|
$this->assertNotSame($data, $encryptedData); |
60
|
|
|
$decryptedData = $crypt->decryptByKey($encryptedData, $key); |
61
|
|
|
$this->assertEquals($data, $decryptedData); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function testEncryptAndDecryptByKeyWithInfo(): void |
65
|
|
|
{ |
66
|
|
|
$crypt = $this->getCrypt(); |
67
|
|
|
$data = 'known data'; |
68
|
|
|
$key = random_bytes(80); |
69
|
|
|
|
70
|
|
|
$encryptedData = $crypt->encryptByKey($data, $key, $key); |
71
|
|
|
$decryptedData = $crypt->decryptByKey($encryptedData, $key, $key); |
72
|
|
|
$this->assertEquals($data, $decryptedData); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
public function testEncryptAndDecryptByKeyShouldThrowExceptionForTamperedData(): void |
76
|
|
|
{ |
77
|
|
|
$crypt = $this->getCrypt(); |
78
|
|
|
$data = 'known data'; |
79
|
|
|
$key = random_bytes(80); |
80
|
|
|
|
81
|
|
|
$this->expectException(AuthenticationException::class); |
82
|
|
|
|
83
|
|
|
$encryptedData = $crypt->encryptByKey($data, $key, $key); |
84
|
|
|
$tampered = $encryptedData; |
85
|
|
|
$tampered[20] = ~$tampered[20]; |
86
|
|
|
$crypt->decryptByKey($tampered, $key); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
public function testEncryptAndDecryptByKeyShouldThrowExceptionForTamperedDataWithNullByte(): void |
90
|
|
|
{ |
91
|
|
|
$crypt = $this->getCrypt(); |
92
|
|
|
$data = 'known data'; |
93
|
|
|
$key = random_bytes(80); |
94
|
|
|
|
95
|
|
|
$this->expectException(AuthenticationException::class); |
96
|
|
|
|
97
|
|
|
$encryptedData = $crypt->encryptByKey($data, $key, $key); |
98
|
|
|
$tampered = $encryptedData; |
99
|
|
|
$tampered[20] = ~$tampered[20]; |
100
|
|
|
$crypt->decryptByKey($encryptedData, $key, $key . "\0"); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* @return array ciphertexts generated using Yii 2.0.2 which is based on mcrypt |
105
|
|
|
*/ |
106
|
|
|
public function dataProviderEncryptByKeyCompatibilityWithMcrypt(): array |
107
|
|
|
{ |
108
|
|
|
return [ |
109
|
|
|
[ |
110
|
|
|
'b86b7529a525d148cc73798da528d8a0', |
111
|
|
|
'30', |
112
|
|
|
'4fb4765bea6beb208ba9395bf6d7497f37626463323730396362366338376536 |
113
|
|
|
3236656535613035373835323061343031613764393062353439623834353135 |
114
|
|
|
376435383635393065393636656663378807b00020ea10101bbfc2ef0dfee082 |
115
|
|
|
fcbc1927daee7e6d061bc7a7c8d8e877', |
116
|
|
|
], |
117
|
|
|
[ |
118
|
|
|
'7e214bb6b27108918c007c0f9e1bdd8a', |
119
|
|
|
'30313233343536373839', |
120
|
|
|
'98981d39f0c985aca577e2eb9472059339623332343335646634613630616335 |
121
|
|
|
6133323639663336633533313032353164393562303434623533326331653561 |
122
|
|
|
6566346561643066643331393437623366e93fe0ef0a220ef1228be9f9195475 |
123
|
|
|
eb303b841b6371841126c13ed419d931', |
124
|
|
|
], |
125
|
|
|
[ |
126
|
|
|
'c139f67915206b7296bc6ab383a2786c', |
127
|
|
|
'303132333435363738396162636465', |
128
|
|
|
'5773028f2be0df720cb3be2cb989e9e161616430393538363437623862326264 |
129
|
|
|
6436336133643738333866353339393932326432356433306630663062613331 |
130
|
|
|
386666313033626661333065313031623d5e980deacb6369592c90e7afca6e6b |
131
|
|
|
06736654378cc93b2d238e6360969956', |
132
|
|
|
], |
133
|
|
|
[ |
134
|
|
|
'910c052157953194d552e3a3f0061ab7', |
135
|
|
|
'30313233343536373839616263646566', |
136
|
|
|
'3141c48cc0b73ee43d5cd9ae5c8a153f66343039333638396632653239623434 |
137
|
|
|
3162616664636331316238336265626536336231653764663732396638336138 |
138
|
|
|
34636438616265376138613539656164b004dd4ebddba049ae068936643dd475 |
139
|
|
|
c07696b0cc173c2eb4c2d7bc3364845e6e3656b463b04e2271cb10824f1365ec', |
140
|
|
|
], |
141
|
|
|
[ |
142
|
|
|
'28d0ad09ce367ca8e0772bbeeea6c40d', |
143
|
|
|
'3031323334353637383961626364656630', |
144
|
|
|
'1f19013959a0985cf0235c4ff46a20c135626235633437383532343736613963 |
145
|
|
|
3765646334666263323832643438663361323266303264383337613736363133 |
146
|
|
|
666432373632343236313331656362354de2203149f8b4f348c06ea4e2eb94e5 |
147
|
|
|
de4deaf1d198e14e7c448421002bdfa9ed979502d86750d70aebaa1c727ae79e', |
148
|
|
|
], |
149
|
|
|
[ |
150
|
|
|
'b658ac4b9fa13c3c1d40699aba886b7b', |
151
|
|
|
'4e161a1df6', |
152
|
|
|
'154015ebb822a55869721a0b1c22497762653266663264333631373938653539 |
153
|
|
|
3465316466396535343966373738666663646232656163383733633739323334 |
154
|
|
|
316363623562353462363133623134643d118216985ac7e3f6888a95552b6a67 |
155
|
|
|
6ff70daf8dfb65b4d5f62a936b7f64d7', |
156
|
|
|
], |
157
|
|
|
[ |
158
|
|
|
'baeb43072f20af0f85c6252aa9f0d472', |
159
|
|
|
'5862447074634952357761764253733d', |
160
|
|
|
'beb6dcd0fb444cbf759a241bd0ea26e537336135333532656136653262303736 |
161
|
|
|
3061656635326136376230333132663839626431366265363565643064616362 |
162
|
|
|
39633830313066356330653466613232dd9cfe4f4495f34a971a25d881dd48a3 |
163
|
|
|
12093a6307a87e4544e217cf9d39dd536a5882d2b9867abefef5c1dad127447e', |
164
|
|
|
], |
165
|
|
|
[ |
166
|
|
|
'd527f854e8f37c49c71b82c48d8b4775', |
167
|
|
|
'82c2f315c69f20ec7ae391fc6c2de85281d54c97f74981b4efec0f5e4606765c |
168
|
|
|
040f1f45386bed4fdb9f998b0e7027c7414bea667b1205027c55eed927364446 |
169
|
|
|
3b1832bc5338e3a7e10bf24d8e69f167b94551b6240f65b416feebd28599334a |
170
|
|
|
a4', |
171
|
|
|
'baa84c2c05b2ac8efd9fc8f9824efb5d63306366393939626532323532646433 |
172
|
|
|
6539346265383936336262303339336635333164383339326436376631353366 |
173
|
|
|
6433616639653638393063376137626574bd7aa8c5f313e2d8b7a4ca4af35090 |
174
|
|
|
9695845c9d62cd91c486307d3ae0701e4abd1fa69a255aab1e6ac2874fa1bc0a |
175
|
|
|
065340418a6669427bcdec751300ce7666a38d17d850f7dae4ea9567045356e8 |
176
|
|
|
f347941226bf7b2d4dd3a21c8aa0b381f8ad06c3a55a7d2cb967ad148142c287 |
177
|
|
|
f12a563f9cd2c6224e7efb8fdd130bb9', |
178
|
|
|
], |
179
|
|
|
[ |
180
|
|
|
'01025bfec21dda4342809cf20382de29', |
181
|
|
|
'badec0c7d9ca734e161a1df6ca4daa8cdbf6b3bbb60ec404b47a23226ec266b1 |
182
|
|
|
3837ffc969e9c23e2bbba72facb491a6a3271193a35026a9ebc93698d689bf7b |
183
|
|
|
84fc384f544cc5d71c2945c8c48ae6348c753322fcaf75171b7d8f1e178e8545 |
184
|
|
|
3d5c79f03bae6d9705cabbe7004ec81e188812a66313297fcf5d4c61a48614d2 |
185
|
|
|
1b5379fae60736f88bc737257bc1cfbef7016108dd1f3a537aaa681544f5bb20 |
186
|
|
|
c2d352212d6a2e460311ab7b93b611218b30c7402709bff89ecf814310c2db97 |
187
|
|
|
81f4142a54d6d41f82c33208c188a023c70befd697b496efb7c7b8569474a9d5 |
188
|
|
|
025a8ea8311c831b3de2b81800f28589b6aef537f6ada2e3d92a1ddd39cfd6b4 |
189
|
|
|
8113c8b36be890b099ca4e08655db0e9b5c211e706af052b776924233321412c |
190
|
|
|
b1b540f08d88acd664c55854b05e31a15d4b0dc93b4514f62a88c3d4a451fe34 |
191
|
|
|
74d2fbaee742f232959b5f6c2b71a8b6ad95a0d5362f39309aca710f37a4dae2 |
192
|
|
|
228e27d35f4d3fc87ee6ece4538587fad7835f9803f5ca64dfd856ae767a3482 |
193
|
|
|
c2f315c69f20ec7ae391fc6c2de85281d54c97f74981b4efec0f5e4606765c04 |
194
|
|
|
0f1f45386bed4fdb9f998b0e7027c7414bea667b1205027c55eed9273644463b |
195
|
|
|
1832bc5338e3a7e10bf24d8e69f167b94551b6240f65b416feebd28599334aa4 |
196
|
|
|
d998a599053cd477f54fc0af62a8ef75eb91096b153751b201b8374c4956508c |
197
|
|
|
6c82ea2ceb0265e74c96032787fe01139b578c3a14fd4e32a85195375b25da60 |
198
|
|
|
4f21187ee01df6042971d7c2b9dd8b611527377f28f933559f6b2edfe7bd8896 |
199
|
|
|
00627830bcdffcb884989013585cc6da726c7cc57c69e8664a244d234465f2a5 |
200
|
|
|
e736512a65e563a2a726915b50247aff165190c75d151139f2b31211a3acf94e |
201
|
|
|
236d27b441fe64e88a443778359d57ba0fed8edbb01cc60a116f9599da4e47bf |
202
|
|
|
e96850ac12d1199a080f1b591c60eae613fba444f9fe31fd42ee333678532556 |
203
|
|
|
07fbfeef02cdbb2d0a8d2329adc7fba22aa4cd124c6e66e0b0aca796ba6aeb69 |
204
|
|
|
f8e76a9d1aaabe351bc42fefa6054977859b51158ba7143980d76db5b2cc6aec |
205
|
|
|
9f83eac5edf79357632fb60cb4811e71892436e582375860faf8d8c518ee33ca |
206
|
|
|
e08b18af7faa227d97196d7b041bcb366118751fbeaa92d80f86324ce8711cfd |
207
|
|
|
65005cad0ce30878f508eb1ea2735e212ef3e42a78467d4f31b483087c3c63a3 |
208
|
|
|
2fa62f2ae92e2acdfc3cf21b3419acc347ff51ccb17161e829cc4a24965fd930 |
209
|
|
|
b983d63153b9c13dd85340d7184bf01734d4357c1aabfbdc9711193ffa974832 |
210
|
|
|
4f88cf801f35708db0901ffaa55415ca4334678633dda763b5fbfba7cfd51dc5 |
211
|
|
|
79149ec9284a4db2349dbc5264d5fca7a72034261716d90a996cb57ba09f7d07 |
212
|
|
|
29a2f10cc58eec98d86e9306a3fbf2e711046e86b5a86cc0eed7625be1a01ebf', |
213
|
|
|
'08ad33a166a9b39ba7522ccf5414123062643565356136373131666663323763 |
214
|
|
|
3636343466313761356339656234343064626331343366346432343062626634 |
215
|
|
|
3264393630336535353431613338653717747da97dd4d63e215dc8bb9ce231d5 |
216
|
|
|
b3cc9c287dfadb1b5acce0d4da2816de16114665271204188d91b642cdfdb494 |
217
|
|
|
66a89caa29a9139354f69c4c188d76d88d36d14004268f327c98f4736ba31728 |
218
|
|
|
a46d8f50d1665bcf157e3164d756286eceac4ce81ba3ffd1b79ff0862f5f529b |
219
|
|
|
d44f0e2fbcb88c388095cb894fd4ce059ba8f5436f0a15b2fa9a40acd6645ad1 |
220
|
|
|
c6f16365250715cb0552dcfc220e844ba67e2a1206b1725a6bbb8f0e87b7067f |
221
|
|
|
b51fc0226cd963bddf549227d5eaf5f996061d9c3b7e3306bd9be1114aed6199 |
222
|
|
|
6e44ee1144bebfca9a1064d40419837e54006f54161dd028b2702faa5cde214c |
223
|
|
|
bc11ed1c77d4042b333e772473f4764fcdfcabdd0319f33d96ad0ab904cd2620 |
224
|
|
|
31683afc4c96dc27fde0570aaedc922a552d46687a606bb579b6ab8050f418f8 |
225
|
|
|
f6a3fc33ef5eeba8dbf54b5a90a1034ff8a68d9ea691d9a1d6b8f41376735bec |
226
|
|
|
6c0f541f927cf107f2184f96235a6fca6d1db013966d8527389f8a79f4afd7bb |
227
|
|
|
297c85d56f74faaa069679edc78b16b17ab8d72de3788f2ac2fe8a2e15ddfb3f |
228
|
|
|
14ffd9ef18c95acf340f702a974b580cac93928417650b8f9e7409619774e483 |
229
|
|
|
af66b18ec7547f744099e2bb4125905e5dd553beca90d03fa7d7bba201ab97ac |
230
|
|
|
92506c305ff79afe9c99a73cb20b9048464beeb100df0ecfb40161f95dd8708a |
231
|
|
|
6fd09e1b166f1e27429b1ca50f990a45425dec25b2a29dcde4fd1c23b0d660ba |
232
|
|
|
10241bc20cdc59c3609a7d6b094538d56b878c62dca3a54fbc53d815ae0549f6 |
233
|
|
|
978ea37a644add2bd2720b37a3502d683b0a8b9ce269bb3db8a44f3e8c3ba507 |
234
|
|
|
7759de171e1d040dfe5c9a610e21e3b41d95403654122ed7b75111622f14bb50 |
235
|
|
|
fd7a3e637bba73fc8c4e22702b52329c224860a9e04b38b8c23527c732a281dc |
236
|
|
|
f92103d71decf673b3fa83feab2c1937811e0b41163019e1b45e664d4acc570c |
237
|
|
|
2d4b24dc138285478c3898b0567c026a1651bbada0fb62ab5ce0d96e3601aec1 |
238
|
|
|
c6f04ecb1b53f1d852893edb971703dcd919c2dd883d0851e2fc491cf9abf1b7 |
239
|
|
|
c1652bac73a5a9e9bdbf164db948cc5b8299fd7f5535fa927130dc4e183ef35e |
240
|
|
|
bb08723625e4cf62f253111e6f016e6cfba2e9cec30e273e4b2dcefa80d1c528 |
241
|
|
|
82c91609acf5989eec18afbefc25c898763c50d2a5cc54250d2672a39758f948 |
242
|
|
|
1866c26d260bf774db05280697d2b1a95b0481afa2b80bb205186ac290bc3770 |
243
|
|
|
b19a652dc2f5d6611363cd851d921edad36851d64f4cac6ff67299455e120cee |
244
|
|
|
65a0d9471d1c952d7e81ba5e67e0a8a41a9a68f50d88a2b62151b564ffc2e435 |
245
|
|
|
8373e55df6cad337589a89054c050f93b4b252aa65466029313bf7311ae735a5 |
246
|
|
|
26cd2bac41af846c069ed614485cf62bd66c939dfeb27ecaaa197aa344a5488b |
247
|
|
|
b3a2dca884c7fdc4ac08816b2b5ba3b7414f7ff7a06a3a6fe75e20c9eb97a881 |
248
|
|
|
ac130616f176d1f26ae24bf4392e0a0e', |
249
|
|
|
], |
250
|
|
|
]; |
251
|
|
|
} |
252
|
|
|
|
253
|
|
|
/** |
254
|
|
|
* @return array ciphertexts generated using openssl |
255
|
|
|
*/ |
256
|
|
|
public function dataProviderEncryptByKeyCompatibilityWithOpenSsl(): array |
257
|
|
|
{ |
258
|
|
|
return [ |
259
|
|
|
[ |
260
|
|
|
'67ae7370e4a144523543f1e3edf35b26', |
261
|
|
|
'30', |
262
|
|
|
'706e1670ec6beb91c565299710e4f43231336530323838313435653933623539 |
263
|
|
|
3238313639623066323530646630653236313832333361346664623132393436 |
264
|
|
|
34326131663964636634366665306439e6142bf3d0e6a5952231d8bfabbacd83 |
265
|
|
|
ff04c61400529385d63a4b8f8696982d', |
266
|
|
|
], |
267
|
|
|
[ |
268
|
|
|
'5d4bae62bea3c8f4c49dd1a38a4e1b2a', |
269
|
|
|
'30313233343536373839', |
270
|
|
|
'4c9a34e1977dd656fd3e18d4bc2b00c762353830326262373135396530643235 |
271
|
|
|
3332643937653632353331626532373336653761643866646233336365323233 |
272
|
|
|
30633138663034313665653038306161eb77ac98344a0bf946f98e892e6e15db |
273
|
|
|
b9e221a7c25135a36562c3ecb2981fcd', |
274
|
|
|
], |
275
|
|
|
[ |
276
|
|
|
'6832851af3c63a1e303bdf1bca38dd9c', |
277
|
|
|
'303132333435363738396162636465', |
278
|
|
|
'd09d2faa163e774abd020bf8cd623f8962646233313330626133613964353834 |
279
|
|
|
3436663631383139653438326563623537373830663962303531366130383130 |
280
|
|
|
3333303531613337386534626136636415db7a6885b67f69d9974f5879ae7497 |
281
|
|
|
08811fc036508f23f55f3f9d16b9ff9d', |
282
|
|
|
], |
283
|
|
|
[ |
284
|
|
|
'e8a9799f4254b26484ea447918dcaad4', |
285
|
|
|
'30313233343536373839616263646566', |
286
|
|
|
'1a76a05af572abe9b4e7a67d7f64baff39666636363332323133373034386531 |
287
|
|
|
3761353236333263643965313139303666636535343862363737333032323331 |
288
|
|
|
313136366562336535663033316231303811542783f13798b17d40aa7ec9b489 |
289
|
|
|
34404ab50784ad1722f5f4d4462f702d3a625ef712635b274a970a47b516b137', |
290
|
|
|
], |
291
|
|
|
[ |
292
|
|
|
'27cbf5a7c4327582393b2ec277cfe957', |
293
|
|
|
'3031323334353637383961626364656630', |
294
|
|
|
'60e2e14b404c5bd55b192ef2f1c7131c32356261636361313131336265323534 |
295
|
|
|
3439623033346337346133346239363337633736663831343632626638303038 |
296
|
|
|
64653361396366356165633061666538d2137b2defca383668827b6983f86254 |
297
|
|
|
bd849c3e8c9a44b6e1ed203491d73b4cb0cb83658240a89baa9261755d707879', |
298
|
|
|
], |
299
|
|
|
[ |
300
|
|
|
'7b157beb08e8a8ac7d74f789ccbacae5', |
301
|
|
|
'4e161a1df6', |
302
|
|
|
'a17ca346c4a88404b8a345b1d075173a66356137326335343137393136353762 |
303
|
|
|
3930636535636466336534316438376437376639366535666636313235653262 |
304
|
|
|
38393464663134313430333633343232b319ce688676fde03d092d73df75705f |
305
|
|
|
bde594d9b2bfe41580a458555982dc70', |
306
|
|
|
], |
307
|
|
|
[ |
308
|
|
|
'88704df5b4881d2246388dc7c68066cc', |
309
|
|
|
'5862447074634952357761764253733d', |
310
|
|
|
'9069fbdd47ee81faf34eff40f8fee94333393037333936333439653537636132 |
311
|
|
|
6561613863336165333336323562353161636330366438633264376461626563 |
312
|
|
|
3836363462646536323261333034643070e4b0a3d196f36a4afb92a7ae4ef7b8 |
313
|
|
|
eb44e9db29638fa32140e379ae7aa6b7e68f454635ade137165383fd3a5c049b', |
314
|
|
|
], |
315
|
|
|
[ |
316
|
|
|
'1d203fba1cd2a7b92abb8f40eb985538', |
317
|
|
|
'82c2f315c69f20ec7ae391fc6c2de85281d54c97f74981b4efec0f5e4606765c |
318
|
|
|
040f1f45386bed4fdb9f998b0e7027c7414bea667b1205027c55eed927364446 |
319
|
|
|
3b1832bc5338e3a7e10bf24d8e69f167b94551b6240f65b416feebd28599334a |
320
|
|
|
a4', |
321
|
|
|
'fade5d841aa10a29a2ef5236371ffc2964343165383664636264393666383364 |
322
|
|
|
6165646139316438666531633230306537343364336166666463656466306564 |
323
|
|
|
63326239653938303332656464346463136bd6dd0b7530490b91024ed944bc3e |
324
|
|
|
3fc4050d20ce05a9ed992ede75f62bdd2523d0cbc93493baf07ef98c895a353b |
325
|
|
|
5baaf26200572aa2e5bd22508db227556c5ee9eb7425418e9852c595e6ac0e61 |
326
|
|
|
37c186e04a3f19d855d8c4b8a8e6ad1be179ea5c816fe461a4cec212297873c8 |
327
|
|
|
5f96ee5c024cd88d1c32975fd95acd73', |
328
|
|
|
], |
329
|
|
|
[ |
330
|
|
|
'1f93719d7a66a724c3841835fbcb33fd', |
331
|
|
|
'badec0c7d9ca734e161a1df6ca4daa8cdbf6b3bbb60ec404b47a23226ec266b1 |
332
|
|
|
3837ffc969e9c23e2bbba72facb491a6a3271193a35026a9ebc93698d689bf7b |
333
|
|
|
84fc384f544cc5d71c2945c8c48ae6348c753322fcaf75171b7d8f1e178e8545 |
334
|
|
|
3d5c79f03bae6d9705cabbe7004ec81e188812a66313297fcf5d4c61a48614d2 |
335
|
|
|
1b5379fae60736f88bc737257bc1cfbef7016108dd1f3a537aaa681544f5bb20 |
336
|
|
|
c2d352212d6a2e460311ab7b93b611218b30c7402709bff89ecf814310c2db97 |
337
|
|
|
81f4142a54d6d41f82c33208c188a023c70befd697b496efb7c7b8569474a9d5 |
338
|
|
|
025a8ea8311c831b3de2b81800f28589b6aef537f6ada2e3d92a1ddd39cfd6b4 |
339
|
|
|
8113c8b36be890b099ca4e08655db0e9b5c211e706af052b776924233321412c |
340
|
|
|
b1b540f08d88acd664c55854b05e31a15d4b0dc93b4514f62a88c3d4a451fe34 |
341
|
|
|
74d2fbaee742f232959b5f6c2b71a8b6ad95a0d5362f39309aca710f37a4dae2 |
342
|
|
|
228e27d35f4d3fc87ee6ece4538587fad7835f9803f5ca64dfd856ae767a3482 |
343
|
|
|
c2f315c69f20ec7ae391fc6c2de85281d54c97f74981b4efec0f5e4606765c04 |
344
|
|
|
0f1f45386bed4fdb9f998b0e7027c7414bea667b1205027c55eed9273644463b |
345
|
|
|
1832bc5338e3a7e10bf24d8e69f167b94551b6240f65b416feebd28599334aa4 |
346
|
|
|
d998a599053cd477f54fc0af62a8ef75eb91096b153751b201b8374c4956508c |
347
|
|
|
6c82ea2ceb0265e74c96032787fe01139b578c3a14fd4e32a85195375b25da60 |
348
|
|
|
4f21187ee01df6042971d7c2b9dd8b611527377f28f933559f6b2edfe7bd8896 |
349
|
|
|
00627830bcdffcb884989013585cc6da726c7cc57c69e8664a244d234465f2a5 |
350
|
|
|
e736512a65e563a2a726915b50247aff165190c75d151139f2b31211a3acf94e |
351
|
|
|
236d27b441fe64e88a443778359d57ba0fed8edbb01cc60a116f9599da4e47bf |
352
|
|
|
e96850ac12d1199a080f1b591c60eae613fba444f9fe31fd42ee333678532556 |
353
|
|
|
07fbfeef02cdbb2d0a8d2329adc7fba22aa4cd124c6e66e0b0aca796ba6aeb69 |
354
|
|
|
f8e76a9d1aaabe351bc42fefa6054977859b51158ba7143980d76db5b2cc6aec |
355
|
|
|
9f83eac5edf79357632fb60cb4811e71892436e582375860faf8d8c518ee33ca |
356
|
|
|
e08b18af7faa227d97196d7b041bcb366118751fbeaa92d80f86324ce8711cfd |
357
|
|
|
65005cad0ce30878f508eb1ea2735e212ef3e42a78467d4f31b483087c3c63a3 |
358
|
|
|
2fa62f2ae92e2acdfc3cf21b3419acc347ff51ccb17161e829cc4a24965fd930 |
359
|
|
|
b983d63153b9c13dd85340d7184bf01734d4357c1aabfbdc9711193ffa974832 |
360
|
|
|
4f88cf801f35708db0901ffaa55415ca4334678633dda763b5fbfba7cfd51dc5 |
361
|
|
|
79149ec9284a4db2349dbc5264d5fca7a72034261716d90a996cb57ba09f7d07 |
362
|
|
|
29a2f10cc58eec98d86e9306a3fbf2e711046e86b5a86cc0eed7625be1a01ebf', |
363
|
|
|
'712929635f5be013159aec81296b96ec36333734373565366166383031313734 |
364
|
|
|
3331623863663837343237633863376539643865643339383531363139396566 |
365
|
|
|
34313731633765393462663264316130de90698e64fa4abc91639e72baee83bc |
366
|
|
|
2caf85f91318e0cbd0db5fa08c4ffb582ec55ca43de53a43f2844af35d5f87b9 |
367
|
|
|
8faa623107aee2e083f1c7aeedcb0472c93bb9eacbd39d839d5bf94c44658d7f |
368
|
|
|
d70817f5d6b120f91ef86880f93e99151bc1ed13ed263a3ccc7243e5ea97f39f |
369
|
|
|
1ce2ce6b05a2b78f05c5d72041e35466068f52fb3d2ba3afa7594d7bc0981c54 |
370
|
|
|
8b31ae7e5b7e7e0e6f2fac9a336e6516d7e4b5cc658e1fe634daf9ad097715be |
371
|
|
|
14d54ef19adc381db31db78714a09e997dc7732853d39885566e41a2c0ecb08d |
372
|
|
|
ef8ab56359a0e312446d9f1555539ad29e13080d438d6817280d4dbfe6cd4ab9 |
373
|
|
|
4a357dbddcea1bc90e0d0fa6d556b1ba75c23a1d3818ea91e0fa5b8005b8020e |
374
|
|
|
f7a80ed2ee60aa8ee588e101dbf3b64bf6a3dca5b1d5bcb96eed5c594bab1dcf |
375
|
|
|
c1f61d74ad3ff0f5fdf176a327e8de33d123cdd61c6c4dc946429c566ac0f77f |
376
|
|
|
48215d5889365fa664a879babd4758fb4d824cfb9e4bf6500ffec0e4ebefe4f6 |
377
|
|
|
2e521a7cd563fc954a9161047461e4054f324c5cf4f9e949566c9ac17c45aac1 |
378
|
|
|
abf98caed42242c51aa0d81d732c538e437c4024e8f04eeeab6619aed46599e7 |
379
|
|
|
f66c2041e0c346affab1f79cd7352a66686fac2b38615f8fc172ab0967fd4435 |
380
|
|
|
9dea9f41b57ba5a752e20456f2254e8eef576867ebda0f48fe47a2e91fc8d8af |
381
|
|
|
dc1bf98a8d3530b4b02996fe4b05ec3dab200f9e79a4261c233caa9a33762f1f |
382
|
|
|
4b3482ab6f16f5dbd7bd87ed17e21c30140ce61fc2468c054ce51dded2683d7c |
383
|
|
|
375d69d662729d6fb8629b8dc25dcc5596f87f627a2138a3ef368a2a1591902f |
384
|
|
|
84ffc457bd556a346815986f153fd3a99ef169444436ac81853b318c0908cb33 |
385
|
|
|
cf332edadfb870cab419365312c18aeda418b8b571783a6b2d8c397c33a22b31 |
386
|
|
|
55958cef153f4d9cfc3a1c6288ff17bfdd92132e1f1e5fe8041e30a383084811 |
387
|
|
|
fe892d7fc33abff10dd20db07277677b16e7f90137adfc3cb36dd85de3618769 |
388
|
|
|
bf8f3ce13642f9ea430f455d388281208190b335915e256320274a904ecd0938 |
389
|
|
|
d3c34d99c88e3186a132777fc7b74b43efab1a08376035061de56a4fb6de611c |
390
|
|
|
41d2139c77a516c4f8144b123696356b4b9a752a9cd857630af4ef02339172e6 |
391
|
|
|
361a2fd6a18e3baaf8a3f7e9811ad5fb61abba7ae893b1e7748df2c5b7704eb9 |
392
|
|
|
65606b0253cba6a0561b0e70593c724f99e07d3e9a857aef894a64a35969b354 |
393
|
|
|
4726d35504d7b8c0c06cbf9106c5d504674daa879b39328d2c83e0f4e5622ea1 |
394
|
|
|
4fb742458214b410e2736d8cefabfb125c4769701711c15ab870b5ff192d4c71 |
395
|
|
|
e805ac5100352e33227b162ebae123e20c477719c52c59e192c2e3731806404d |
396
|
|
|
d4359f840b11ad495357210e259e6b9e8fe5e8f600e8746fe1a483d45b694324 |
397
|
|
|
0809649ed7320b0022a5ef7b414635933d6d18ec7218f829121d12dcb573ed77 |
398
|
|
|
79ab0519d2df17dbd8988b32ac0711ef', |
399
|
|
|
], |
400
|
|
|
]; |
401
|
|
|
} |
402
|
|
|
|
403
|
|
|
/** |
404
|
|
|
* @dataProvider dataProviderEncryptByKeyCompatibilityWithMcrypt |
405
|
|
|
* |
406
|
|
|
* @param string $key encryption key hex string |
407
|
|
|
* @param string $data plaintext hex string |
408
|
|
|
* @param string $encrypted ciphertext hex string |
409
|
|
|
* @throws \Exception |
410
|
|
|
*/ |
411
|
|
|
public function testEncryptByKeyCompatibilityWithMcrypt(string $key, string $data, string $encrypted): void |
412
|
|
|
{ |
413
|
|
|
$crypt = $this->getCrypt(); |
414
|
|
|
|
415
|
|
|
$key = hex2bin(preg_replace('{\s+}', '', $key)); |
416
|
|
|
$data = hex2bin(preg_replace('{\s+}', '', $data)); |
417
|
|
|
$encrypted = hex2bin(preg_replace('{\s+}', '', $encrypted)); |
418
|
|
|
|
419
|
|
|
$this->assertEquals($data, $crypt->decryptByKey($encrypted, $key)); |
420
|
|
|
} |
421
|
|
|
|
422
|
|
|
/** |
423
|
|
|
* @dataProvider dataProviderEncryptByKeyCompatibilityWithOpenSsl |
424
|
|
|
* |
425
|
|
|
* @param string $key encryption key hex string |
426
|
|
|
* @param string $data plaintext hex string |
427
|
|
|
* @param string $encrypted ciphertext hex string |
428
|
|
|
* @throws \Exception |
429
|
|
|
*/ |
430
|
|
|
public function testEncryptByKeyCompatibilityWithOpenSsl(string $key, string $data, string $encrypted): void |
431
|
|
|
{ |
432
|
|
|
$crypt = $this->getCrypt(); |
433
|
|
|
|
434
|
|
|
$key = hex2bin(preg_replace('{\s+}', '', $key)); |
435
|
|
|
$data = hex2bin(preg_replace('{\s+}', '', $data)); |
436
|
|
|
$encrypted = hex2bin(preg_replace('{\s+}', '', $encrypted)); |
437
|
|
|
|
438
|
|
|
$this->assertEquals($data, $crypt->decryptByKey($encrypted, $key)); |
439
|
|
|
} |
440
|
|
|
|
441
|
|
|
/** |
442
|
|
|
* @return array ciphertexts generated using Yii 2.0.2 which is based on mcrypt |
443
|
|
|
*/ |
444
|
|
|
public function dataProviderEncryptByPasswordMcryptCompatibility(): array |
445
|
|
|
{ |
446
|
|
|
return [ |
447
|
|
|
[ |
448
|
|
|
'LtogIEhy59ve0Huy', |
449
|
|
|
'30', |
450
|
|
|
'83325c8abe8dc0afd801acb7785dc29c32393439653930663266396466653862 |
451
|
|
|
3965303964653935326238343065363734346264633932376364376430653933 |
452
|
|
|
37303963376232336634306339396136e6f4e7dc3e2fd23be186f037e4caa6d0 |
453
|
|
|
4ae8cb894d80c08bb790417af9cc176f', |
454
|
|
|
], |
455
|
|
|
[ |
456
|
|
|
'1_VTumNNc7VV463t', |
457
|
|
|
'30313233343536373839', |
458
|
|
|
'a247ac24f3aa60e894904f58954ce8bf39386530366165343538336132616231 |
459
|
|
|
6532353066663430646432383531333465373336646333386437323733633763 |
460
|
|
|
646665346232623635393962626162323a44a150a556addd97addfb43a32f600 |
461
|
|
|
aa2c479664682a308e6cdd523967cb4a', |
462
|
|
|
], |
463
|
|
|
[ |
464
|
|
|
'DBpoIPndKRm2Rfem', |
465
|
|
|
'303132333435363738396162636465', |
466
|
|
|
'9ed20f30824312032e5e34e2c5ab61e333313930616634396137623261363863 |
467
|
|
|
3334323832333664626265663435643633323033383862613865633961356261 |
468
|
|
|
30353634393536636465643833633531b62ce156f34b92790b2d26312f3fd7d0 |
469
|
|
|
0a646da4d636f6998f1b0d859f255dc6', |
470
|
|
|
], |
471
|
|
|
[ |
472
|
|
|
's1e1oRE1iM_oortb', |
473
|
|
|
'30313233343536373839616263646566', |
474
|
|
|
'5b03427dba481b5af8760edc3788fa0e66666663623539353163346466663761 |
475
|
|
|
6434663337383566366265663931303662366530653633663235303532373763 |
476
|
|
|
37346330393537646630616535373230c98134da00d77753741c1f0bb483f109 |
477
|
|
|
622a889f950310cd51d7d48d63202b20d378eac85f7d0c851fc9905d322aef96', |
478
|
|
|
], |
479
|
|
|
[ |
480
|
|
|
'i1E7JvOQaESAKoeH', |
481
|
|
|
'3031323334353637383961626364656630', |
482
|
|
|
'7cf2ed4612d07de3ecfd54ac0e576e8539613861656439333965623533626238 |
483
|
|
|
3361653764663438643330383130313462613961636462383836383862313962 |
484
|
|
|
346439313666343336313766366538637bd566b1eecb0b1e0896eb1fd0fd11d9 |
485
|
|
|
dcb9eee5cc3d90c4046a6849e8ad152caf85e8f96de3b24b4d523a2d60533e0b', |
486
|
|
|
], |
487
|
|
|
[ |
488
|
|
|
'QUN24gpNGodXurMM', |
489
|
|
|
'4e161a1df6', |
490
|
|
|
'49fc2d51b3e6325d86334ea8872699ef31613661333031373065373834643033 |
491
|
|
|
3863343734366435343035316562643438636133306233373431323066333330 |
492
|
|
|
32613330623364326162326434306637042f9b4a005ed3b9532181d020378800 |
493
|
|
|
deefcfa36d77ed4abdf35546c0bb4aec', |
494
|
|
|
], |
495
|
|
|
[ |
496
|
|
|
'1COt9D8ZsfclCic2', |
497
|
|
|
'5862447074634952357761764253733d', |
498
|
|
|
'c4d5f90054faf3699d983795f44bdb1430643734643832343265323064323434 |
499
|
|
|
6535346565323733323764376266646539366431353266666639386231626438 |
500
|
|
|
653237646165393461626435656332332b4244fccb47ad8cdea56109c7d5a417 |
501
|
|
|
13b3844d9857507db59d0000037b169f7b67cf0ea793c0254bffc55342d8e4c7', |
502
|
|
|
], |
503
|
|
|
[ |
504
|
|
|
'eUqmv4chMnO1H5cq', |
505
|
|
|
'82c2f315c69f20ec7ae391fc6c2de85281d54c97f74981b4efec0f5e4606765c |
506
|
|
|
040f1f45386bed4fdb9f998b0e7027c7414bea667b1205027c55eed927364446 |
507
|
|
|
3b1832bc5338e3a7e10bf24d8e69f167b94551b6240f65b416feebd28599334a |
508
|
|
|
a4', |
509
|
|
|
'31435e0bf8c0be9a395791288f6d058839336130623938343839626436636433 |
510
|
|
|
6664373131666361383739633163373130323936653730306331663836373263 |
511
|
|
|
656135303466323439326564626162378298df437dab821e8b2f7086962ffeb1 |
512
|
|
|
7a674022ee498470e5e8fdff8905aed39e424588ecee69965bb6856f0356860e |
513
|
|
|
aa978ffa42ccfef6d4fb00026014e107736f3ee9b2206a2cd52b18e3068cf6aa |
514
|
|
|
077c7304128a3cd92d4fc29dfa7c180eaf85feec791618db1ed01695536cf8ec |
515
|
|
|
7923c0b3fb974fd0ff92faa62723e94f', |
516
|
|
|
], |
517
|
|
|
[ |
518
|
|
|
'3Cl5v2Lmn61PiQ3H', |
519
|
|
|
'badec0c7d9ca734e161a1df6ca4daa8cdbf6b3bbb60ec404b47a23226ec266b1 |
520
|
|
|
3837ffc969e9c23e2bbba72facb491a6a3271193a35026a9ebc93698d689bf7b |
521
|
|
|
84fc384f544cc5d71c2945c8c48ae6348c753322fcaf75171b7d8f1e178e8545 |
522
|
|
|
3d5c79f03bae6d9705cabbe7004ec81e188812a66313297fcf5d4c61a48614d2 |
523
|
|
|
1b5379fae60736f88bc737257bc1cfbef7016108dd1f3a537aaa681544f5bb20 |
524
|
|
|
c2d352212d6a2e460311ab7b93b611218b30c7402709bff89ecf814310c2db97 |
525
|
|
|
81f4142a54d6d41f82c33208c188a023c70befd697b496efb7c7b8569474a9d5 |
526
|
|
|
025a8ea8311c831b3de2b81800f28589b6aef537f6ada2e3d92a1ddd39cfd6b4 |
527
|
|
|
8113c8b36be890b099ca4e08655db0e9b5c211e706af052b776924233321412c |
528
|
|
|
b1b540f08d88acd664c55854b05e31a15d4b0dc93b4514f62a88c3d4a451fe34 |
529
|
|
|
74d2fbaee742f232959b5f6c2b71a8b6ad95a0d5362f39309aca710f37a4dae2 |
530
|
|
|
228e27d35f4d3fc87ee6ece4538587fad7835f9803f5ca64dfd856ae767a3482 |
531
|
|
|
c2f315c69f20ec7ae391fc6c2de85281d54c97f74981b4efec0f5e4606765c04 |
532
|
|
|
0f1f45386bed4fdb9f998b0e7027c7414bea667b1205027c55eed9273644463b |
533
|
|
|
1832bc5338e3a7e10bf24d8e69f167b94551b6240f65b416feebd28599334aa4 |
534
|
|
|
d998a599053cd477f54fc0af62a8ef75eb91096b153751b201b8374c4956508c |
535
|
|
|
6c82ea2ceb0265e74c96032787fe01139b578c3a14fd4e32a85195375b25da60 |
536
|
|
|
4f21187ee01df6042971d7c2b9dd8b611527377f28f933559f6b2edfe7bd8896 |
537
|
|
|
00627830bcdffcb884989013585cc6da726c7cc57c69e8664a244d234465f2a5 |
538
|
|
|
e736512a65e563a2a726915b50247aff165190c75d151139f2b31211a3acf94e |
539
|
|
|
236d27b441fe64e88a443778359d57ba0fed8edbb01cc60a116f9599da4e47bf |
540
|
|
|
e96850ac12d1199a080f1b591c60eae613fba444f9fe31fd42ee333678532556 |
541
|
|
|
07fbfeef02cdbb2d0a8d2329adc7fba22aa4cd124c6e66e0b0aca796ba6aeb69 |
542
|
|
|
f8e76a9d1aaabe351bc42fefa6054977859b51158ba7143980d76db5b2cc6aec |
543
|
|
|
9f83eac5edf79357632fb60cb4811e71892436e582375860faf8d8c518ee33ca |
544
|
|
|
e08b18af7faa227d97196d7b041bcb366118751fbeaa92d80f86324ce8711cfd |
545
|
|
|
65005cad0ce30878f508eb1ea2735e212ef3e42a78467d4f31b483087c3c63a3 |
546
|
|
|
2fa62f2ae92e2acdfc3cf21b3419acc347ff51ccb17161e829cc4a24965fd930 |
547
|
|
|
b983d63153b9c13dd85340d7184bf01734d4357c1aabfbdc9711193ffa974832 |
548
|
|
|
4f88cf801f35708db0901ffaa55415ca4334678633dda763b5fbfba7cfd51dc5 |
549
|
|
|
79149ec9284a4db2349dbc5264d5fca7a72034261716d90a996cb57ba09f7d07 |
550
|
|
|
29a2f10cc58eec98d86e9306a3fbf2e711046e86b5a86cc0eed7625be1a01ebf', |
551
|
|
|
'0c5164ead7f48c5d95f5907399c146a261353462323734323738656231323164 |
552
|
|
|
3962333166373062373734636630623932616638626236393339363861646366 |
553
|
|
|
35643933393537303331343436303330a927c7a879272f81e1032d57530b5e69 |
554
|
|
|
60f70e14b7607e8e17583aa8197f547e375e07b7a9d6c11be406f5e01aac59e2 |
555
|
|
|
7e54bb3c33662ea294cfbd0e7bb8e5eb886edee341509a752fc3b9706807a948 |
556
|
|
|
00edd0bff8e624275420bff50995de70d2692a052e1710a0b9135f9f44abcb02 |
557
|
|
|
24a189f1bb414e4d73fb539728d40b47ebc34fdb5ec2fa61848bb828de5179a1 |
558
|
|
|
e799eb09367bda9b59b3bdc51d3f92c1bd7dacf751b9324059869bf6adc3d88d |
559
|
|
|
226a153a75cae1a2426ea187ef62c97bbd35e97450da87d4da9aed08ebf30a3c |
560
|
|
|
a3369cc65a17acebb8a6ff8ff698743a3782990bc5e8cd03a6882c0f7c50868c |
561
|
|
|
6b3ce967c9ea317555eb972e9bb7beb7b3215160a0bcca8c7f92a085beca256e |
562
|
|
|
4484b1cdcaee495917d8aa4dbf7675806f7f57e77a770ea7db6e080150b43f56 |
563
|
|
|
15709b371a303e89b032eac7fec3ee954ea52940a2e59343fd0fd59ac2d4f095 |
564
|
|
|
74d2863eed13774c63a94e87f7ccdbf0741a56074a7210e2f022809ca48637d8 |
565
|
|
|
057d80fb190f339ddee2b6f7aaef3f2c1848026bd33e377ac554e2b29dede4fc |
566
|
|
|
11e040b3837c24e6cd93430c2f9c19138cd1b505681958a09f223f65e6d7b123 |
567
|
|
|
43e426e204ee32411b1590133d58fbc4806ff784db93cd0205a7b4a1f4b96ee4 |
568
|
|
|
02b06ac00520118c89a7c4f1dfb4ac941a3d6f839e9312ee8cd9c3c02ef5cf2a |
569
|
|
|
29d266fcfd29c24b994bcd3c67000999486bad6b060f87d5c843f3f132be5a7c |
570
|
|
|
6ab2aab2091a83f0673efc4bf658e6c181c800a2eab5272c9cc8e9bdcf4ee061 |
571
|
|
|
de613989f107f1755385697ad64cd1c613f1f742a980c48e27638b8423b82eba |
572
|
|
|
555c59020ee5794099377e816e8983a7579fc97178e5ac0f98bdda6dbf3f38f1 |
573
|
|
|
3f8b2d12cc792e729468a8408482985ac73e831a6ca5f67176f68bf216b77147 |
574
|
|
|
fe4743ae60f628defa590b0b0b7d8c39d24ef6980ffc0c47882fa0e3f04ed3e5 |
575
|
|
|
6d8654e11a0f25a2b3dd03e900e3d59922fa7ccd544f98a04828a34826fd9bfe |
576
|
|
|
e8c841ca6146cc96443ab2cbed3f846f5241d27b15f81df80e2b35219044e933 |
577
|
|
|
4967334529fe949604a19f7cad76842a16928066a01fb9ec750e78ae68ddcb4f |
578
|
|
|
833b5e89377ea31c7c87666c300f36f7583383f783f979cedbd05585c50caade |
579
|
|
|
73f9f38dfcc5f915106573694ce497a0787ce3fecf9678a75b62f258aea300e8 |
580
|
|
|
2176e5c51009ea1fbdf266606cfb93cc62f9abd6c056625df053da8d9e175d63 |
581
|
|
|
ca716f148365a41796889e6d24e6c9a6ee6ac57bf7c35b45d4000ec638d191e5 |
582
|
|
|
54fe6b031f87b82f6076e9672f7162de1dafedb9fed9d38adeb999c7fc46f801 |
583
|
|
|
cd546342404315b06faff51d549b2eb94390d40a9ad826c1595add3f11afb909 |
584
|
|
|
16dc20173f13010008bc12a6355d582205897e7eb885f526a08bee072dabbb15 |
585
|
|
|
3b1777d8e7d96b31db8b64d64404ae82b3506f10ef198fad6321aa8cf04b5f54 |
586
|
|
|
d5236014d4b5ce20fbfba77f090d3573', |
587
|
|
|
], |
588
|
|
|
]; |
589
|
|
|
} |
590
|
|
|
|
591
|
|
|
/** |
592
|
|
|
* @return array ciphertexts generated using openssl |
593
|
|
|
*/ |
594
|
|
|
public function dataProviderEncryptByPasswordOpenSslCompatibility(): array |
595
|
|
|
{ |
596
|
|
|
return [ |
597
|
|
|
[ |
598
|
|
|
'3DZsVH4gt5xBueho', |
599
|
|
|
'30', |
600
|
|
|
'e19edc37d284b77a5a4600334b67317662393266323434393038666330653031 |
601
|
|
|
3730313664646137663830626366383363336239313664336637653133313933 |
602
|
|
|
306133613836363563643538396163642b6c12f20e7e1ae97422ee659914cc57 |
603
|
|
|
e99c7c97c7a4957e78ab957b18be4551', |
604
|
|
|
], |
605
|
|
|
[ |
606
|
|
|
'CVALyUpDdMOSaxJN', |
607
|
|
|
'30313233343536373839', |
608
|
|
|
'a2535797ac0c83932fd9a2b8d6b2602662663439623337616631623434333233 |
609
|
|
|
3033343439313063656162373231666330333261383561356632393932386462 |
610
|
|
|
3631666364313236303962373636316296930828e0e154a0e8d262846835f242 |
611
|
|
|
e42de861cba81df69fe6fe5a5970fdf7', |
612
|
|
|
], |
613
|
|
|
[ |
614
|
|
|
'wBZcBIhNSFiaCWE8', |
615
|
|
|
'303132333435363738396162636465', |
616
|
|
|
'd77b5d334d2820b5b5a54c5f71fce21130373832656561636661623564383766 |
617
|
|
|
6338343636626662346566623035333461653566353366656438303063376561 |
618
|
|
|
32643033343166376162376333373166c6cf828b68ff940e8de977e3471d1d51 |
619
|
|
|
2e51bab7ee0f976dd6d87727b508f7cf', |
620
|
|
|
], |
621
|
|
|
[ |
622
|
|
|
'PYeAhK5nWPIxGD2F', |
623
|
|
|
'30313233343536373839616263646566', |
624
|
|
|
'0c2b35c26794c55b94228af98ba7378133326361353835323130363730333039 |
625
|
|
|
3531343463653763663366386462363733666537646466326339303439373730 |
626
|
|
|
64343038313234393232313362653639dbec4d9abb2dcffbf186366476df34d2 |
627
|
|
|
500744fd27eda1e0ea0e54280b091d32ebd1e786402507cb3c591503e27f195b', |
628
|
|
|
], |
629
|
|
|
[ |
630
|
|
|
'B9u8Tl9tRBgmnSHk', |
631
|
|
|
'3031323334353637383961626364656630', |
632
|
|
|
'8401d45dbce698cf9342152c75cd8f5164356231643534643561646636316462 |
633
|
|
|
6331373265623831373165363336616165343432383161633962646333373932 |
634
|
|
|
3139323034393665303863356331363743e5873d38758489b9d5800aabf31f3e |
635
|
|
|
cf36e1e47955f5c96acdf8dc6cc7280c825949d46546796ec5a114985f5fe598', |
636
|
|
|
], |
637
|
|
|
[ |
638
|
|
|
'cLHX5BvVQcdlozS6', |
639
|
|
|
'4e161a1df6', |
640
|
|
|
'e04aed1dc385788c3c777bc7b3cfa20c32656633363730393363366138643831 |
641
|
|
|
3866303330613461666664623039326437623739613236333566353762333461 |
642
|
|
|
34653132366163653031303134353161eefebead8d190e854c05f598adfb8d7b |
643
|
|
|
ef30c86c7cc7003f261b8ce26c62da55', |
644
|
|
|
], |
645
|
|
|
[ |
646
|
|
|
'r8EZMeBVex-LC3c5', |
647
|
|
|
'5862447074634952357761764253733d', |
648
|
|
|
'ae03ee587e7df6407a17d43e3381b76563616366633165613463383063353930 |
649
|
|
|
6163613736656635663234613263323833393131363661333737333133356366 |
650
|
|
|
3963313236356663373035323264623224b4aa1536a8deba1dfa026efa614fb9 |
651
|
|
|
4915763a2629a00fe5ff8f1afc894f1b644f9b08ebc7baefc06229f177b5e446', |
652
|
|
|
], |
653
|
|
|
[ |
654
|
|
|
'TRS5GvlQ2WCoEzHY', |
655
|
|
|
'82c2f315c69f20ec7ae391fc6c2de85281d54c97f74981b4efec0f5e4606765c |
656
|
|
|
040f1f45386bed4fdb9f998b0e7027c7414bea667b1205027c55eed927364446 |
657
|
|
|
3b1832bc5338e3a7e10bf24d8e69f167b94551b6240f65b416feebd28599334a |
658
|
|
|
a4', |
659
|
|
|
'f05611e02a2cccbfea4679e8110087a061396332303030396562663732626138 |
660
|
|
|
3530363534313362373731316330363964393564653831636566646261363265 |
661
|
|
|
38323536366666633438396566323939bce309f535fca3d1fb23e8503f8cf3b8 |
662
|
|
|
bca4c4bcfb4021592268f88070b5203f5023a6a39034e34048bc944c22e037fd |
663
|
|
|
e6ca8ca17e2bdc8169d1e714830de6932cfe0dcdd1728e8bf848a6f4f7154d1c |
664
|
|
|
0f8c650e0ef650ba3b90372eb6d13e93e3c79610291a523a3967a3049b04f1d4 |
665
|
|
|
c899e1554b04f906c2e6408a16702d19', |
666
|
|
|
], |
667
|
|
|
[ |
668
|
|
|
'x_a2LHnyqH8WAwkZ', |
669
|
|
|
'badec0c7d9ca734e161a1df6ca4daa8cdbf6b3bbb60ec404b47a23226ec266b1 |
670
|
|
|
3837ffc969e9c23e2bbba72facb491a6a3271193a35026a9ebc93698d689bf7b |
671
|
|
|
84fc384f544cc5d71c2945c8c48ae6348c753322fcaf75171b7d8f1e178e8545 |
672
|
|
|
3d5c79f03bae6d9705cabbe7004ec81e188812a66313297fcf5d4c61a48614d2 |
673
|
|
|
1b5379fae60736f88bc737257bc1cfbef7016108dd1f3a537aaa681544f5bb20 |
674
|
|
|
c2d352212d6a2e460311ab7b93b611218b30c7402709bff89ecf814310c2db97 |
675
|
|
|
81f4142a54d6d41f82c33208c188a023c70befd697b496efb7c7b8569474a9d5 |
676
|
|
|
025a8ea8311c831b3de2b81800f28589b6aef537f6ada2e3d92a1ddd39cfd6b4 |
677
|
|
|
8113c8b36be890b099ca4e08655db0e9b5c211e706af052b776924233321412c |
678
|
|
|
b1b540f08d88acd664c55854b05e31a15d4b0dc93b4514f62a88c3d4a451fe34 |
679
|
|
|
74d2fbaee742f232959b5f6c2b71a8b6ad95a0d5362f39309aca710f37a4dae2 |
680
|
|
|
228e27d35f4d3fc87ee6ece4538587fad7835f9803f5ca64dfd856ae767a3482 |
681
|
|
|
c2f315c69f20ec7ae391fc6c2de85281d54c97f74981b4efec0f5e4606765c04 |
682
|
|
|
0f1f45386bed4fdb9f998b0e7027c7414bea667b1205027c55eed9273644463b |
683
|
|
|
1832bc5338e3a7e10bf24d8e69f167b94551b6240f65b416feebd28599334aa4 |
684
|
|
|
d998a599053cd477f54fc0af62a8ef75eb91096b153751b201b8374c4956508c |
685
|
|
|
6c82ea2ceb0265e74c96032787fe01139b578c3a14fd4e32a85195375b25da60 |
686
|
|
|
4f21187ee01df6042971d7c2b9dd8b611527377f28f933559f6b2edfe7bd8896 |
687
|
|
|
00627830bcdffcb884989013585cc6da726c7cc57c69e8664a244d234465f2a5 |
688
|
|
|
e736512a65e563a2a726915b50247aff165190c75d151139f2b31211a3acf94e |
689
|
|
|
236d27b441fe64e88a443778359d57ba0fed8edbb01cc60a116f9599da4e47bf |
690
|
|
|
e96850ac12d1199a080f1b591c60eae613fba444f9fe31fd42ee333678532556 |
691
|
|
|
07fbfeef02cdbb2d0a8d2329adc7fba22aa4cd124c6e66e0b0aca796ba6aeb69 |
692
|
|
|
f8e76a9d1aaabe351bc42fefa6054977859b51158ba7143980d76db5b2cc6aec |
693
|
|
|
9f83eac5edf79357632fb60cb4811e71892436e582375860faf8d8c518ee33ca |
694
|
|
|
e08b18af7faa227d97196d7b041bcb366118751fbeaa92d80f86324ce8711cfd |
695
|
|
|
65005cad0ce30878f508eb1ea2735e212ef3e42a78467d4f31b483087c3c63a3 |
696
|
|
|
2fa62f2ae92e2acdfc3cf21b3419acc347ff51ccb17161e829cc4a24965fd930 |
697
|
|
|
b983d63153b9c13dd85340d7184bf01734d4357c1aabfbdc9711193ffa974832 |
698
|
|
|
4f88cf801f35708db0901ffaa55415ca4334678633dda763b5fbfba7cfd51dc5 |
699
|
|
|
79149ec9284a4db2349dbc5264d5fca7a72034261716d90a996cb57ba09f7d07 |
700
|
|
|
29a2f10cc58eec98d86e9306a3fbf2e711046e86b5a86cc0eed7625be1a01ebf', |
701
|
|
|
'5d841d0cb575fdb8c7e2cc48be47021d38646237366663323933346163643933 |
702
|
|
|
3861336335396666356139383066663033336333303731336263663262626136 |
703
|
|
|
643635333333393362306631333266320d73812258a45d90f8240d59c4e39e87 |
704
|
|
|
8d4d999f36403a6f0b1d69ab9416792c5e8f2cf427af8423c8213a885fde488c |
705
|
|
|
db95217c64c542f5e2be6b4375ff82e5c72a9f165049546b38295006f50665b1 |
706
|
|
|
354350de4a68b5f16a18f7df53e0999f4f7ba5ba0676e416a0444d5b7accda8b |
707
|
|
|
093ae31a23e3cb63b6f404c437071435b8143f282c4cb4403a2b538af5a0d94f |
708
|
|
|
1e582c3bb9d5379ba5d576643854c232d74f303dcac91a711bf440fb24e7ab2a |
709
|
|
|
70ef69008ffb59ad2455d4f1482e77114489a3b5a250384b24062f546f86073a |
710
|
|
|
91fdd85d34bd7814b4ce70ec8d6ea34f98067d7101050f3800f9f1fd92003856 |
711
|
|
|
223f8ca142749c2ef4c8d1991a62b0ff86623bf9afce65d55fb5efe80089cee4 |
712
|
|
|
e4f12e94e1748c5740f075a94a2290ba2dc892fdfde516ebc190a4db63e77f93 |
713
|
|
|
54a3bec5ef695572dddcc9d7c43609724c73bc5bfe79d5f322890e4f39a31e6b |
714
|
|
|
3fb9388c78e133c58e395ca03eca2e8ab9520e4d2e5421e0d9a1f781a564dda7 |
715
|
|
|
720d56f413312762da078e0226053672983ecf5bdf18086a6f617071814d61e4 |
716
|
|
|
27e6f02167b8d38e381607e4238f21c0b6e6d9222f1cc6348b9f7d6fb084cc3b |
717
|
|
|
306b7acbb94f4b3ab6b66fe539865fb804899d3f64c8bca6bd02ee5509022a50 |
718
|
|
|
03d63e259bb414391fc10ae9b2e42c68a2be743488b69ca77c70741820aaeeb0 |
719
|
|
|
da2ff00c07787a39ec613e665d78c30b5f57a14fcbe24f00cf55eeb174e23dac |
720
|
|
|
a9eb3587bc8dc8fdf5ef062b7f1659b45c48246055fda699b6ae8b9fcc46a380 |
721
|
|
|
ebc6b648662ef5fed1a4fe16c9aa310cc16f5ad642b80549262f5c77335f5435 |
722
|
|
|
a43d30459297b754350a9dd635b0ca5342fc798d369225f6d692eea0c901eb72 |
723
|
|
|
fd10af1199b7847ffc1a0c5915902fe339772183727c31497c752e3beb1cf010 |
724
|
|
|
2c97ab270def6628bdae630172d73a9fc0afed1d893870003828f64518512886 |
725
|
|
|
57d62ba52c8d325aa8409b0a40754dc3f84d1c8898e01e20c03464b83d2dae5d |
726
|
|
|
3d9f279778fb1161ac5d8f9c466fd0c6bdd6a21553ea9252ff018ae99b0d4425 |
727
|
|
|
0e55d177fb1e0275da97474ea052d85d96b7432c1be840e5994b127b147d1a0c |
728
|
|
|
64f1cea9115a37225c8b49960e0693680ee5593c81784c850811e1f10ce4f9a3 |
729
|
|
|
365e3d2d240e0eef8da6404d5a93ebd000a98d5d33dd5a238327e88dfdad2744 |
730
|
|
|
ed0c4321a543c1a3231e53550e816c531b73bafec21e32daeecd199c7a2be75f |
731
|
|
|
450ce4d39e10ad81a7ca74877e1661376d7cce557a1d4dde53b503e1512efef6 |
732
|
|
|
d607d5074ca8ba29db067454e529aec867907c6eded03ce90835d72974cddcc5 |
733
|
|
|
83628bd2948a78a2d666ed89889f59b1dd5b05704b7e68a801ad9f93809e0d8a |
734
|
|
|
ae72a72923883d4de81d867bf639eb5dc581429041ca78763235fe11251254c8 |
735
|
|
|
cca8bfe10e8810035e4cce023b6527744d0ea839bb035db99adc3ce742a5491d |
736
|
|
|
c446220a6cb416a0bd3362b424dcdf3e', |
737
|
|
|
], |
738
|
|
|
]; |
739
|
|
|
} |
740
|
|
|
|
741
|
|
|
/** |
742
|
|
|
* @dataProvider dataProviderEncryptByPasswordMcryptCompatibility |
743
|
|
|
* |
744
|
|
|
* @param string $password encryption password |
745
|
|
|
* @param string $data plaintext hex string |
746
|
|
|
* @param string $encrypted ciphertext hex string |
747
|
|
|
* @throws \Exception |
748
|
|
|
*/ |
749
|
|
|
public function testEncryptByPasswordCompatibilityWithMcrypt(string $password, string $data, string $encrypted): void |
750
|
|
|
{ |
751
|
|
|
$crypt = $this->getCrypt(); |
752
|
|
|
|
753
|
|
|
$data = hex2bin(preg_replace('{\s+}', '', $data)); |
754
|
|
|
$encrypted = hex2bin(preg_replace('{\s+}', '', $encrypted)); |
755
|
|
|
|
756
|
|
|
$this->assertEquals($data, $crypt->decryptByPassword($encrypted, $password)); |
757
|
|
|
} |
758
|
|
|
|
759
|
|
|
/** |
760
|
|
|
* @dataProvider dataProviderEncryptByPasswordOpenSslCompatibility |
761
|
|
|
* |
762
|
|
|
* @param string $password encryption password |
763
|
|
|
* @param string $data plaintext hex string |
764
|
|
|
* @param string $encrypted ciphertext hex string |
765
|
|
|
* @throws \Exception |
766
|
|
|
*/ |
767
|
|
|
public function testEncryptByPasswordCompatibilityWithOpenSsl(string $password, string $data, string $encrypted): void |
768
|
|
|
{ |
769
|
|
|
$crypt = $this->getCrypt(); |
770
|
|
|
|
771
|
|
|
$data = hex2bin(preg_replace('{\s+}', '', $data)); |
772
|
|
|
$encrypted = hex2bin(preg_replace('{\s+}', '', $encrypted)); |
773
|
|
|
|
774
|
|
|
$this->assertEquals($data, $crypt->decryptByPassword($encrypted, $password)); |
775
|
|
|
} |
776
|
|
|
|
777
|
|
|
public function testOpensslNotLoadedException() |
778
|
|
|
{ |
779
|
|
|
$this->expectException(\RuntimeException::class); |
780
|
|
|
|
781
|
|
|
MockHelper::$mock_extension_loaded = false; |
|
|
|
|
782
|
|
|
$crypt = $this->getCrypt(); |
|
|
|
|
783
|
|
|
} |
784
|
|
|
|
785
|
|
|
public function testUnknownCipher() |
786
|
|
|
{ |
787
|
|
|
$this->expectException(\RuntimeException::class); |
788
|
|
|
|
789
|
|
|
$crypt = new Crypt('test'); |
|
|
|
|
790
|
|
|
} |
791
|
|
|
|
792
|
|
|
public function testWithKdfAlgorithm() |
793
|
|
|
{ |
794
|
|
|
$crypt = new Crypt('AES-256-CBC'); |
795
|
|
|
$newCrypt = $crypt->withKdfAlgorithm('sha512'); |
796
|
|
|
$this->assertInstanceOf(Crypt::class, $newCrypt); |
797
|
|
|
$this->assertNotSame($crypt, $newCrypt); |
798
|
|
|
$this->assertEquals('AES-256-CBC', $this->getInaccessibleProperty($newCrypt, 'cipher')); |
799
|
|
|
$this->assertEquals('sha512', $this->getInaccessibleProperty($newCrypt, 'kdfAlgorithm')); |
800
|
|
|
} |
801
|
|
|
|
802
|
|
|
public function testWithAuthKeyInfo() |
803
|
|
|
{ |
804
|
|
|
$crypt = new Crypt('AES-256-CBC'); |
805
|
|
|
$newCrypt = $crypt->withAuthKeyInfo('info'); |
806
|
|
|
$this->assertInstanceOf(Crypt::class, $newCrypt); |
807
|
|
|
$this->assertNotSame($crypt, $newCrypt); |
808
|
|
|
$this->assertEquals('AES-256-CBC', $this->getInaccessibleProperty($newCrypt, 'cipher')); |
809
|
|
|
$this->assertEquals('info', $this->getInaccessibleProperty($newCrypt, 'authKeyInfo')); |
810
|
|
|
} |
811
|
|
|
|
812
|
|
|
public function testOpensslEncryptException() |
813
|
|
|
{ |
814
|
|
|
$this->expectException(\RuntimeException::class); |
815
|
|
|
|
816
|
|
|
MockHelper::$mock_openssl_encrypt = false; |
|
|
|
|
817
|
|
|
$crypt = $this->getCrypt(); |
818
|
|
|
$crypt->encryptByPassword('test', 'test'); |
819
|
|
|
} |
820
|
|
|
|
821
|
|
|
public function testOpensslDecryptException() |
822
|
|
|
{ |
823
|
|
|
$this->expectException(\RuntimeException::class); |
824
|
|
|
|
825
|
|
|
MockHelper::$mock_openssl_decrypt = false; |
|
|
|
|
826
|
|
|
$crypt = $this->getCrypt(); |
827
|
|
|
$encrypted = $crypt->encryptByPassword('test', 'test'); |
828
|
|
|
$crypt->decryptByPassword($encrypted, 'test'); |
829
|
|
|
} |
830
|
|
|
} |
831
|
|
|
|
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.