2

I am still new on laravel, and just use laravel package name Crypt

but I found some that there are

Crypt::encrypt

and

Crypt::encryptString

what is the difference between them?

Salim Djerbouh
  • 10,719
  • 6
  • 29
  • 61
Steven Y.
  • 41
  • 1
  • 6
  • 1
    `Crypt::encrypt` : "Encrypted values are passed through serialize during encryption, which allows for encryption of objects and arrays." More info in the doc https://laravel.com/docs/6.x/encryption – Clément Baconnier Nov 01 '19 at 16:06
  • 1
    Consider accepting my answer as correct if it helped you. :-) – Elias Soares Nov 01 '19 at 18:20

1 Answers1

4

You can always refer to source code to know.

See Line 122 of Encrypter.php:

    return $this->encrypt($value, false);

Behind the scenes the encryptString calls the encrypt() method with false as second parameter, meaning that it won't serialize the value you give.

There's no difference in the behavior, but it will encrypt faster and the result will be slightly smaller because it won't contain string serialization.

Elias Soares
  • 9,884
  • 4
  • 29
  • 59
  • 1
    Unless you use it in on a lot of data, I believe the main advantage is that `encryptString` allow a non-PHP application to decrypt the value since serialize is PHP specific – Clément Baconnier Nov 01 '19 at 16:14