Re: [PHP] Upgrading from libmcrypt 2.2.x to 2.4.x

2002-05-03 Thread Cédric Veilleux

Hi,

Thanks for the hint.

Just a small note to let you know that my code to decrypt a string will 
return a string with filled with null characters at the end. You should 
trim() it.

Also, anybody knows how to detect if the PHP build is linked with 2.2 or 2.4? 
I would like my crypt / decrypt functions to detect which mcrypt version is 
used dynamically, so the same code could run with both versions without 
modifications.

Right now the only way I found is to check whether the MCRYPT_RIJNDAEL_128 
constant (or any other cipher type constants) is a number or a string (these 
constants are strings under 2.4.x and numbers under 2.2.x). Any better way of 
doing this?

I've checked the php info functions, they can tell if a certain extension is 
present but this is not very helpful..


Thank you,

Cedric



On May 3, 2002 02:29 am, Tom Rogers wrote:
 Hi
 Thanks for that info, was just what I needed :)
 You can also create $iv with this:

 $iv = pack(a.mcrypt_enc_get_iv_size($td),$iv);

 I use base64_encode() and base64_decode() to store the result and send via
 the web.
 Tom

 At 01:02 PM 3/05/2002, Cédric Veilleux wrote:
 Hi,
 
  I had an hard time converting my code from mcrypt 2.2.x to 2.4.x.
  There is a
 big lack of info about the difference between the two and I could not find
 anything to help me make the move.
 
  My problem was not getting things to work with either version of
  mcrypt,
 there are plenty of examples available for both versions. My problem was
 getting libmcrypt 2.4.x decrypting the data previously encrypted by 2.2.x.
 
  Here's some general info for anyone interested. I would have been
  very
 pleased to find this will searching the archive and I didn't, so I am
  doing it for anybody else facing the same problem.
 
 1) PHP linked with libmcrypt 2.2.x is not too picky about Initialization
 Vectors, but with 2.4.x, it will give a warning message if you don't
  specify one with some of the functions or simply wont work with others.
  Check my example code below to see what I did.
 
 2) PHP will segfault if you use a key size with the wrong lenght with
  2.4.x and it won't with 2.2.x. Be very careful about the lenght of your
  key in 2.4.x, what worked previously might not work now.
 
 
 Decryption under libmcrypt 2.2.x:
 -
 $clear_text = mcrypt_cbc ($cipher, $key, hex2bin($crypted_text),
 MCRYPT_DECRYPT);
 -
 
 Encryption under libmcrypt 2.2.x:
 -
 $crypted_text = bin2hex(mcrypt_cbc ($cipher, $key, $clear_text,
 MCRYPT_ENCRYPT));
 -
 
 
 The following code is what I had to do to get a similar (compatible)
 behaviour
 under libmcrypt 2.4.x. Note that I create an initialization vector filled
 with \0 characters, which is, I believe, the default behavior with
 libmcrypt 2.2.x. The PHP manual somewhere recommends to use 0 if you do
  not want to use an initialization vector. This did not work for me, as
  this is not the default 2.2.x behavior. I think the manual should be
  modified as it greatly confiused me.
 
 Encryption under libmcrypt 2.4.x:
 -
 $td = mcrypt_module_open ($cipher, , MCRYPT_MODE_CBC, );
 $i = 0;
 while ($i  mcrypt_enc_get_iv_size ($td)) {
  $iv .= \0;
  $i++;
 }
 mcrypt_generic_init ($td, $key, $iv);
 $crypted_text = bin2hex(mcrypt_generic($td, $plain_text));
 mcrypt_generic_end ($td);
 -
 
 Decryption under libmcrypt 2.4.x:
 -
 $td = mcrypt_module_open ($cipher, , MCRYPT_MODE_CBC, );
 $i = 0;
 while ($i  mcrypt_enc_get_iv_size ($td)) {
  $iv .= \0;
  $i++;
 }
 mcrypt_generic_init ($td, $key, $iv);
 $plain_text = mdecrypt_generic($td, hex2bin($crypted_text));
 mcrypt_generic_end ($td);
 -
 
 
 In these snippets, $crypted_text is the encrypted data in hexadecimal
  format. This allows data to be stored (in DB's for example) or displayed
  without problems. You need the following function:
 
 function hex2bin($data) {
  $len = strlen($data);
  return pack(H . $len, $data);
 }
 
 
 
 Hope this can help someone..
 
 
 Thank you,
 
 Cedric
 
 
 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Re: PHP and SOAP

2002-05-03 Thread Cédric Veilleux

Udo,

Could you point us to the SOAP classes you've come accross? I am in 
the same 
situation as you are but haven't found much yet. There is indeed a SOAP 
server class from Manuel available at phpclasses.org, this is the first one 
I've seen. I haven't found a SOAP client class yet.

The lack of SOAP implementations in PHP made me think that I'd better 
use 
XMLRPC instead, which is a similar protocol that has been around longer. 
There is a PHP extension available for XMLRPC

http://www.php.net/manual/en/ref.xmlrpc.php


Thank you,

Cedric


On May 3, 2002 04:55 am, Quentin Bennett wrote:
 Hi,

 Let Manuel be your friend!

 http://www.phpclasses.org/

 Quentin

 Udo Giacomozzi [EMAIL PROTECTED] wrote in message
 [EMAIL PROTECTED]">news:[EMAIL PROTECTED]...

  Probably this question has been asked a couple of times but I could not
  find a complete answer to my question...
 
  I am new to PHP but have a lot of experience with Delphi and usually have
  no problems learning new languages (besides PHP is very similar to C). I
  also made already some little PHP scripts or modified larger scripts to
  suit my needs. Anyway...
 
  I need to write a web service in PHP. On the client side there will be a
  Delphi program that accesses the server via SOAP. I choose PHP on the
  server side because it (1) offers more possibilities to extend the
  product later on and (2) because it is less problematic with installation
  issues and platform support. The most work will be anyway the client so
  it should not be too difficult to write the server.
 
 
  Now the simple question:
 
  What SOAP server implementation for PHP do you suggest me? I know there

 are

  several projects being developed on but I really don't know which one I
  should use to begin my tests with or - in other words - to learn.
 
  I hope you can give me more information on this subject. :-)
 
  Many thanks in advance,
  Udo
 
 
 
  --
  Udo Giacomozzi - [EMAIL PROTECTED]
  www.nova-sys.net - www.guweb.com
  The disadvantage of intelligence is that one
  is constantly obliged to go on learning.
 
  Posted by ELKNews 1.0.4-B
  Empower your News Reader! http://www.atozedsoftware.com


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP] Upgrading from libmcrypt 2.2.x to 2.4.x

2002-05-02 Thread Cédric Veilleux

Hi,

I had an hard time converting my code from mcrypt 2.2.x to 2.4.x. There is a 
big lack of info about the difference between the two and I could not find 
anything to help me make the move.

My problem was not getting things to work with either version of mcrypt, 
there are plenty of examples available for both versions. My problem was 
getting libmcrypt 2.4.x decrypting the data previously encrypted by 2.2.x.

Here's some general info for anyone interested. I would have been very 
pleased to find this will searching the archive and I didn't, so I am doing 
it for anybody else facing the same problem.

1) PHP linked with libmcrypt 2.2.x is not too picky about Initialization 
Vectors, but with 2.4.x, it will give a warning message if you don't specify 
one with some of the functions or simply wont work with others. Check my 
example code below to see what I did.

2) PHP will segfault if you use a key size with the wrong lenght with 2.4.x 
and it won't with 2.2.x. Be very careful about the lenght of your key in 
2.4.x, what worked previously might not work now.


Decryption under libmcrypt 2.2.x:
-
$clear_text = mcrypt_cbc ($cipher, $key, hex2bin($crypted_text), 
MCRYPT_DECRYPT);
-

Encryption under libmcrypt 2.2.x:
-
$crypted_text = bin2hex(mcrypt_cbc ($cipher, $key, $clear_text, 
MCRYPT_ENCRYPT));
-


The following code is what I had to do to get a similar (compatible) behaviour 
under libmcrypt 2.4.x. Note that I create an initialization vector filled 
with \0 characters, which is, I believe, the default behavior with 
libmcrypt 2.2.x. The PHP manual somewhere recommends to use 0 if you do not 
want to use an initialization vector. This did not work for me, as this is 
not the default 2.2.x behavior. I think the manual should be modified as it 
greatly confiused me.

Encryption under libmcrypt 2.4.x:
-
$td = mcrypt_module_open ($cipher, , MCRYPT_MODE_CBC, );
$i = 0;
while ($i  mcrypt_enc_get_iv_size ($td)) {
$iv .= \0;
$i++;
}
mcrypt_generic_init ($td, $key, $iv);
$crypted_text = bin2hex(mcrypt_generic($td, $plain_text));
mcrypt_generic_end ($td);
-

Decryption under libmcrypt 2.4.x:
-
$td = mcrypt_module_open ($cipher, , MCRYPT_MODE_CBC, );
$i = 0;
while ($i  mcrypt_enc_get_iv_size ($td)) {
$iv .= \0;
$i++;
}
mcrypt_generic_init ($td, $key, $iv);
$plain_text = mdecrypt_generic($td, hex2bin($crypted_text));
mcrypt_generic_end ($td);
-


In these snippets, $crypted_text is the encrypted data in hexadecimal format. 
This allows data to be stored (in DB's for example) or displayed without 
problems. You need the following function:

function hex2bin($data) {
$len = strlen($data);
return pack(H . $len, $data);
}



Hope this can help someone..


Thank you,

Cedric


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php