Ciaran Synnott
Ciaran Synnott

Reputation: 23

Encrypted string to Byte Array

I'm encrypting a string using this function;

$encrypted_body = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, utf8_encode($body), MCRYPT_MODE_CBC, $iv); 
//Encrypting using MCRYPT_RIJNDAEL_256 algorithm  

I then get my encrypted string.

What i need to do next is convert this string into a Byte Array. How do I do this? I've played with the pack/unpack features but am not having any luck!

Any help would be great.

Thanks in Advance!

Upvotes: 0

Views: 895

Answers (1)

deceze
deceze

Reputation: 522519

PHP does not have byte arrays. What other languages call byte arrays are just a string of bytes one after the other, which can be accessed by their offset. PHP strings in fact do the same thing:

$encrypted_body[0]  ->  first byte
$encrypted_body[1]  ->  second byte
$encrypted_body[n]  ->  n+1th byte

So, just use PHP strings for the same purpose.

Upvotes: 1

Related Questions