How to encrypt id using eloquent orm and slim

392 views Asked by At

Can anyone explain how to encrypt id using eloquent.Present i am using thirdparty library to encrypt and decrypt id.I want know how to encrypt and decrypt ids using eloquent orm in slim.

1

There are 1 answers

1
Jonas Staudenmeir On

Encrypting ids is a terrible idea. It doesn't provide any security and is bad for performance.

Encryption is only meant for sensitive data (e.g. credit card numbers). Ids are just unique identifiers and don't contain any sensitive information (or least shouldn't). If you need an identifier for a private URL, generate a random token and store it in a separate column.

Encrypting an integer with Laravel gives you a string with ~190 characters. You shouldn't use that as a primary/foreign key.

Since Laravel's encrypter uses CBC Mode, encrypting the same value gives you a different result each time. So you can't use Model::find($id) to retrieve an entry from the database. You would have to fetch and decrypt all ids to find the right one.