MCrypt not decrypting simple text

This is a discussion on MCrypt not decrypting simple text within the PHP General forums, part of the PHP Programming Forums category; I'm using MCrypt and I have two very simple functions. All I'm doing is giving the function some ...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 03-20-2008
Dan
 
Posts: n/a
Default MCrypt not decrypting simple text

I'm using MCrypt and I have two very simple functions. All I'm doing is
giving the function some text and a password, it encrypts the text and saves
it as a text file on the server. Then I at some later time run another php
file which decrypts using the decrypt function given the text and the SAME
password as the first time and all I get is garbage. What am I doing wrong?
What do I need to change so that I can get this to work the way I described?

function aes_128_encrypt($text,$password) {

$size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC);
$iv = mcrypt_create_iv($size, MCRYPT_DEV_RANDOM);

$text .= chr(3).chr(3).chr(3);

return bin2hex(mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $password, $text,
MCRYPT_MODE_ECB, $iv));

} // End of function

and

function aes_128_decrypt($encrypted_text,$password) {

$size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC);
$iv = mcrypt_create_iv($size, MCRYPT_DEV_RANDOM);

return mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $password, pack("H*",
$encrypted_text), MCRYPT_MODE_ECB, $iv);

} // End of function


- Dan

Reply With Quote
  #2 (permalink)  
Old 03-22-2008
Dan
 
Posts: n/a
Default Re: MCrypt not decrypting simple text

Ok, looks like I'm not getting much intrest here, can anyone recomend which
newsgroup I should post this under? Is there a crypto group or anything of
the like?:

- Dan

""Dan"" <frozendice@gmail.com> wrote in message
news:AB.E9.09437.752D2E74@pb1.pair.com...
> I'm using MCrypt and I have two very simple functions. All I'm doing is
> giving the function some text and a password, it encrypts the text and
> saves it as a text file on the server. Then I at some later time run
> another php file which decrypts using the decrypt function given the text
> and the SAME password as the first time and all I get is garbage. What am
> I doing wrong? What do I need to change so that I can get this to work the
> way I described?
>
> function aes_128_encrypt($text,$password) {
>
> $size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC);
> $iv = mcrypt_create_iv($size, MCRYPT_DEV_RANDOM);
>
> $text .= chr(3).chr(3).chr(3);
>
> return bin2hex(mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $password,
> $text, MCRYPT_MODE_ECB, $iv));
>
> } // End of function
>
> and
>
> function aes_128_decrypt($encrypted_text,$password) {
>
> $size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC);
> $iv = mcrypt_create_iv($size, MCRYPT_DEV_RANDOM);
>
> return mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $password, pack("H*",
> $encrypted_text), MCRYPT_MODE_ECB, $iv);
>
> } // End of function
>
>
> - Dan


Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 11:34 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0