Page 1 of 1
encrypt decrypt of a string that is not a division of 8
Posted: Wed Sep 30, 2009 5:00 am
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.
Re: encrypt decrypt of a string that is not a division of 8
Posted: Wed Sep 30, 2009 5:09 am
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
Re: encrypt decrypt of a string that is not a division of 8
Posted: Wed Sep 30, 2009 5:12 am
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!
Re: encrypt decrypt of a string that is not a division of 8
Posted: Wed Sep 30, 2009 5:16 am
by arjan.top
you can't change that, it depends on the cipher used
rtrim($decrypted_data, "\0") should work
Re: encrypt decrypt of a string that is not a division of 8
Posted: Wed Sep 30, 2009 5:26 am
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.
Re: encrypt decrypt of a string that is not a division of 8
Posted: Wed Sep 30, 2009 1:25 pm
by Meni
Worked like a charm.
Thank you for your help!!!!
Re: encrypt decrypt of a string that is not a division of 8
Posted: Fri Oct 02, 2009 12:33 am
by kaisellgren
Or use CTR, which works by XORing the plain-text with the output of the block cipher (Triple DES in your case).