File tree Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Original file line number Diff line number Diff line change @@ -1346,6 +1346,28 @@ public function hash(string $algorithm)
1346
1346
return new static (hash ($ algorithm , $ this ->value ));
1347
1347
}
1348
1348
1349
+ /**
1350
+ * Encrypt the string.
1351
+ *
1352
+ * @param bool $serialize
1353
+ * @return static
1354
+ */
1355
+ public function encrypt (bool $ serialize = false )
1356
+ {
1357
+ return new static (encrypt ($ this ->value , $ serialize ));
1358
+ }
1359
+
1360
+ /**
1361
+ * Decrypt the string.
1362
+ *
1363
+ * @param bool $serialize
1364
+ * @return static
1365
+ */
1366
+ public function decrypt (bool $ serialize = false )
1367
+ {
1368
+ return new static (decrypt ($ this ->value , $ serialize ));
1369
+ }
1370
+
1349
1371
/**
1350
1372
* Dump the string.
1351
1373
*
Original file line number Diff line number Diff line change 2
2
3
3
namespace Illuminate \Tests \Support ;
4
4
5
+ use Illuminate \Container \Container ;
6
+ use Illuminate \Encryption \Encrypter ;
5
7
use Illuminate \Support \Carbon ;
6
8
use Illuminate \Support \Collection ;
7
9
use Illuminate \Support \HtmlString ;
13
15
14
16
class SupportStringableTest extends TestCase
15
17
{
18
+ protected Container $ container ;
19
+
16
20
/**
17
21
* @param string $string
18
22
* @return \Illuminate\Support\Stringable
@@ -1438,4 +1442,16 @@ public function testHash()
1438
1442
$ this ->assertSame (hash ('xxh3 ' , 'foobar ' ), (string ) $ this ->stringable ('foobar ' )->hash ('xxh3 ' ));
1439
1443
$ this ->assertSame (hash ('sha256 ' , 'foobarbaz ' ), (string ) $ this ->stringable ('foobarbaz ' )->hash ('sha256 ' ));
1440
1444
}
1445
+
1446
+ public function testEncryptAndDecrypt ()
1447
+ {
1448
+ Container::setInstance ($ this ->container = new Container );
1449
+
1450
+ $ this ->container ->bind ('encrypter ' , fn () => new Encrypter (str_repeat ('b ' , 16 )));
1451
+
1452
+ $ encrypted = encrypt ('foo ' );
1453
+
1454
+ $ this ->assertNotSame ('foo ' , $ encrypted );
1455
+ $ this ->assertSame ('foo ' , decrypt ($ encrypted ));
1456
+ }
1441
1457
}
You can’t perform that action at this time.
0 commit comments