IshaS
IshaS

Reputation: 837

How to use different keys for different users when encrypt in Laravel?

I try to encrypt files in Laravel5.7

$encryptedContent = encrypt($fileContent);

worked for encrypt the files.

$decryptedContent = base64_encode(decrypt($encryptedContent));

worked for decrypt.

My problem is I need to use different keys for different user for encrypt the files and decrypt. I tried the following way.

$crypt = new \Illuminate\Encryption\Encrypter($newkey);
$encryptedContent = $crypt->encrypt($fileContent);

But it gives following error.

The only supported ciphers are AES-128-CBC and AES-256-CBC with the correct key lengths

Can anyone please help me? Thanks.

Upvotes: 0

Views: 385

Answers (1)

IshaS
IshaS

Reputation: 837

The problem was with key length.

If we use AES-128-CBC key should be 16 character length and AES-256-CBC 32 character length.

Upvotes: 2

Related Questions