Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Help with hex initialization vector

2:18 am on Mar 29, 2011 (gmt 0)

Hello everyone,

I am being requested to generate an initialization vector in hex code (16 characters) and I am unsure of a few things; I'm using this code to generate and echo the IV:

$size = mcrypt_get_iv_size(MCRYPT_CAST_256, MCRYPT_MODE_CFB);
$iv = mcrypt_create_iv($size, MCRYPT_DEV_RANDOM);
echo $iv;

But what I get looks like this:


My questions:

1. Is it supposed to be displayed with those unusual characters?
2. If yes to question #1 and that's how its supposed to be, there are 15 characters there, how can I make it 16 characters long?

I got caught in a complete new topic here, any help will be greatly welcome,


EDIT: When displayed in this forum it looks different than what I get in my page.
12:15 am on Mar 30, 2011 (gmt 0)

Could someone help me a little here please?

5:33 pm on Mar 30, 2011 (gmt 0)

WebmasterWorld Administrator coopster is a WebmasterWorld Top Contributor of All Time 10+ Year Member

  1. Yes, it's encrypted.
  2. Use mcrypt_enc_get_iv_size [php.net] to see the size of the IV of the opened algorithm. I have never trimmed the IV. Leave that alone. Use the "get encrypted iv size" functions during decrypt to substring that part off the payload data.