Jakir Hosen Khan
Jakir Hosen Khan

Reputation: 1528

What is the maximum size allowed data (text fo be encripted) by mcrypt_generic() of php?

I have a string to encrypt and then decrypt the encrypted string. I can do this using the following function of php

   string mcrypt_generic ( resource $td , string $data );

Successfully if $data size is 60MB . But I need to encrypt/decrypt file larger then 1GB. For larger database I got **Memory out of range ** error. I have the following configuration,

 ini_set('memory_limit', '2048M'); // 2GB

But got same error. Please suggest how can I do this.

Thanks.

Upvotes: 1

Views: 174

Answers (1)

Narf
Narf

Reputation: 14762

That error message is not emitted by PHP, ext/mcrypt or libmcrypt ... not directly at least, it is likely caused by a PHP bug and not the result of a pre-set limit.

But regardless, such large files should be handled one small chunk at a time. You can read, for example, up to 4kb from the source file, encrypt that small portion of it, append the result to the target file - repeat that in a loop until you've processed all of it.

That is just an example of course, but you should take it as one for how to handle large files in general. If you want to encrypt something, I'd suggest you use an existing, proven tool that does all of it for you, otherwise there are just too many details to handle that you're not even aware of.

Upvotes: 1

Related Questions