Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Limit Laravel 5 Encryption length

I have a Laravel5 web application of Business directory.

When I Encrypting a value like

$cryptval = Crypt::encrypt(1);

result  =  eyJpdiI6IndhaFZFNlhIRDlURzdXanJVMEhBM0E9PSIsInZhbHVlIjoidWF3VzRFZDhyRHltUlwveDdyV0VVWnc9PSIsIm1hYyI6IjE5YjA2YWIyN2Q0MTBlYjdhNDJiNDE5ZjY2OGQ2MDA2NzQ3ZTA4ODc4NzY0ZTIwMjBiMzQxN2RjNmM5ZDg3ZjYifQ==

its giving a long string about 250 length.

Is there any way to limit the length of this string in laravel?

My Client needs to add the URL with encrypted value in a mail function. eg:

www.example.com/varify/eyJpdiI6IndhaFZFNlhIRDlURzdXanJVMEhBM0E9PSIsInZhbHVlIjoidWF3VzRFZDhyRHltUlwveDdyV0VVWnc9PSIsIm1hYyI6IjE5YjA2YWIyN2Q0MTBlYjdhNDJiNDE5ZjY2OGQ2MDA2NzQ3ZTA4ODc4NzY0ZTIwMjBiMzQxN2RjNmM5ZDg3ZjYifQ==

But the mail function only allow some length of URL :(

like image 299
Jishad P Avatar asked Oct 19 '15 09:10

Jishad P


People also ask

What is encryption in Laravel?

The process of converting cipher text to plain text is called Decryption. Laravel uses AES-256 and AES-128 encrypted, which uses Open SSL for encryption. All the values included in Laravel are signed using the protocol Message Authentication Code so that the underlying value cannot be tampered with once it is encrypted.

How to limit the length of a string in Laravel?

There are many different ways to limit the length of a string. For example, you could use CSS, JavaScript, or do it through PHP. Laravel also provides a nice helper to make this easy! We will be using the Str class from Illuminate\Support\Str namespace. Get helpful Laravel tutorials & freebies into your inbox. This post is submitted by our members.

How to convert cipher text to plain text in Laravel?

The process of converting cipher text to plain text is called Decryption. Laravel uses AES-256 and AES-128 encrypted, which uses Open SSL for encryption.

What is Laravel authentication scaffold?

Laravel is a perfectly curated PHP Frameworks that's been contributed and used by thousands of developers and software companies around the globe. It has come a long way and so has Laravel Authentication Scaffold. It's one of the core feature of Laravel that the Laravel community boast about and adore. Yes it's just a Scaffold.


Video Answer


2 Answers

One solution is to store the hashed values in a table, and then reference the hash by the auto-incrementing ID of the hash value.

| id | hash             | timestamp | random_key |
| 1  | some-hash        | 125346164 | 21415      |
| 2  | some-other-hash  | 123513515 | 25151      |

So now, instead of using:

www.example.com/verify/some-hash

You can use:

www.example.com/verify/1

The id should really be obfuscated, and not used just as an integer - which is where the timestamp and random_key can help.

$id = 1;
$timestamp = 125346164;
$randomKey = 21415;

$key = base64_encode($timestamp . $randomKey . $id);

echo 'http://www.domain.com/verify/' . $key;

// http://www.domain.com/verify/MTI1MzQ2MTY0MjE0MTUx

All that being said, my recommendation would be to try to work around the limitation put in place by the e-mail delivery platform as URL's can support an address length of around 2000 characters. The example you gave only had a length of 32 and falls well within the lengths acceptable by any modern browser.

Edit: Just generate a uuid using a package like this rather than trying to create your own random id. This will produce a string such as d3d29d70-1d25-11e3-8591-034165a3a613.

like image 119
Amo Avatar answered Oct 13 '22 21:10

Amo


I think dont need to store nothing in database, that is a hard work, In my case a use base64_encode in blase and use base64_decode in controller to show the real value to method and continue the process.

like image 33
Albertino Carvalho Avatar answered Oct 13 '22 21:10

Albertino Carvalho