encrypt decrypt of a string that is not a division of 8

Discussions of secure PHP coding. Security in software is important, so don't be afraid to ask. And when answering: be anal. Nitpick. No security vulnerability is too small.

Moderator: General Moderators

Post Reply
Meni
Forum Newbie
Posts: 12
Joined: Wed Apr 19, 2006 3:55 pm

encrypt decrypt of a string that is not a division of 8

Post by Meni »

I have been having an issue

Code: Select all

mcrypt_encrypt(MCRYPT_TripleDES, $key, $string, MCRYPT_MODE_CBC, $iv);

Code: Select all

mcrypt_decrypt(MCRYPT_TripleDES, $key, $enc_string, MCRYPT_MODE_CBC, $iv)

and $iv = '';

when I input a string that is less than 8 (like 12345) characters i get [12345???]

Why is that? Is it because $iv = ''; ?

Thanks,
Meni.
User avatar
arjan.top
Forum Contributor
Posts: 305
Joined: Sun Oct 14, 2007 4:36 am
Location: Hoče, Slovenia

Re: encrypt decrypt of a string that is not a division of 8

Post by arjan.top »

ciphers work on blocks of data, if the data is not long enough it would pad the data to the required length
Meni
Forum Newbie
Posts: 12
Joined: Wed Apr 19, 2006 3:55 pm

Re: encrypt decrypt of a string that is not a division of 8

Post by Meni »

arjan.top wrote:ciphers work on blocks of data, if the data is not long enough it would pad the data to the required length
Ok, thank you for this.
Is it possible to set the block size to 1? Any reason not to?
If not - how do I encrypt my 5 digit number and the decrypt it to get the 5 digits ONLY?

Thanks!
User avatar
arjan.top
Forum Contributor
Posts: 305
Joined: Sun Oct 14, 2007 4:36 am
Location: Hoče, Slovenia

Re: encrypt decrypt of a string that is not a division of 8

Post by arjan.top »

you can't change that, it depends on the cipher used

rtrim($decrypted_data, "\0") should work
Meni
Forum Newbie
Posts: 12
Joined: Wed Apr 19, 2006 3:55 pm

Re: encrypt decrypt of a string that is not a division of 8

Post by Meni »

arjan.top wrote:you can't change that, it depends on the cipher used

rtrim($decrypted_data, "\0") should work
Thank you. I will give it a try.
Meni
Forum Newbie
Posts: 12
Joined: Wed Apr 19, 2006 3:55 pm

Re: encrypt decrypt of a string that is not a division of 8

Post by Meni »

Worked like a charm.
Thank you for your help!!!!
User avatar
kaisellgren
DevNet Resident
Posts: 1675
Joined: Sat Jan 07, 2006 5:52 am
Location: Lahti, Finland.

Re: encrypt decrypt of a string that is not a division of 8

Post by kaisellgren »

Or use CTR, which works by XORing the plain-text with the output of the block cipher (Triple DES in your case).
Post Reply