Question

I've noticed that both openssl and mcrypt functions in PHP accept data to be encrypted as strings only. This means a value of (int)1234567890 is converted and encrypted as a 10-byte string when it was originally just a 4-byte int. Are there any encryption methods (bundled with PHP or as an external function/class) that allows for the encryption of integers?

Was it helpful?

Solution

No. If you want to encrypt your integer as the 4-byte binary representation, then you have to preconvert it:

$bin = pack("L", $int);    // unsigned 4-byte integer
xyz_crypt(...)

And unpack this again after decryption.

OTHER TIPS

mcrypt operates on strings, not integers, so you'll need to use pack() to, well, pack an integer into a 4-byte string. (The inverse function is, sensibly enough, unpack().)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top