php-general Digest 31 Jul 2006 19:02:30 -0000 Issue 4267

Topics (messages 239890 through 239928):

Re: sorting in array
        239890 by: Peter Lauri
        239891 by: weetat
        239892 by: Paul Novitski
        239893 by: Paul Novitski
        239894 by: Paul Novitski
        239895 by: weetat
        239896 by: weetat
        239897 by: weetat
        239898 by: Paul Novitski
        239899 by: Peter Lauri
        239900 by: Peter Lauri
        239902 by: David Tulloh

Nested foreach statement
        239901 by: Chris Grigor
        239916 by: chris smith

memory leak - how to find it?
        239903 by: Robin Getz
        239905 by: David Tulloh
        239911 by: chris smith

AES client side
        239904 by: Andrew Senyshyn
        239906 by: Andrei
        239907 by: Jay Blanchard
        239908 by: Thomas Munz
        239909 by: tedd
        239910 by: Andrei
        239912 by: zerof
        239913 by: Jon Anderson
        239915 by: Jay Blanchard
        239918 by: Jon Anderson
        239919 by: Jay Blanchard
        239920 by: Jon Anderson
        239921 by: Jay Blanchard
        239922 by: Colin Guthrie
        239923 by: Kilbride, James P.
        239924 by: Jon Anderson
        239925 by: Jay Blanchard
        239926 by: Jon Anderson
        239927 by: Robin Vickery
        239928 by: Jon Anderson

Error Loading php module
        239914 by: Brad Bonkoski

Re: mb_substr()
        239917 by: Al

Administrivia:

To subscribe to the digest, e-mail:
        [EMAIL PROTECTED]

To unsubscribe from the digest, e-mail:
        [EMAIL PROTECTED]

To post to the list, e-mail:
        [email protected]


----------------------------------------------------------------------
--- Begin Message ---
   function cmpcountry($a, $b)
   {

         $country1 = $a['country'];
         $country2 = $b['country'];

           if($country1=='') return 1;
           else return ($country1 < $country2) ? -1 : 1;

   }

-----Original Message-----
From: weetat [mailto:[EMAIL PROTECTED] 
Sent: Monday, July 31, 2006 12:32 PM
To: [email protected]
Subject: [PHP] sorting in array

Hi all ,

  I have array value as shown below, i have paste my test php code below:
  I have problem when doing usort() when 'country' = '', i would like to 
display records where country = '' last. Any ideas how to do that ?

Thanks

   $arraytest= array(
      array
         (
             'country' => '',
         )
      ,
      array
         (
             'country' => 'Thailand',
         )
      ,
      array
         (
             'country' => 'Singapore',
         )
      ,
      array
         (
             'country' => 'Singapore',
         )
      ,
      array
         (
             'country' => '',
         )
       ,
          array
         (
             'country' => '',
         )
        ,
        array
         (
             'country' => '',
         )

      );


   function cmpcountry($a, $b)
   {

         $country1 = $a['country'];
         $country2 = $b['country'];

          return ($country1 < $country2) ? -1 : 1;
   }

     usort($arraytest,"cmpcountry");
     while(list($name,$value)=each($arraytest)){
           echo $name."<br><br>";

           while(list($n,$v) = each($arraytest[$name])){
               echo $v."<br><br>";
           }
      }

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

--- End Message ---
--- Begin Message ---

Hi ,

  Doesn't work .
  Any ideas ?

Thanks
Peter Lauri wrote:
   function cmpcountry($a, $b)
   {

         $country1 = $a['country'];
         $country2 = $b['country'];

           if($country1=='') return 1;
           else return ($country1 < $country2) ? -1 : 1;

   }

-----Original Message-----
From: weetat [mailto:[EMAIL PROTECTED] Sent: Monday, July 31, 2006 12:32 PM
To: [email protected]
Subject: [PHP] sorting in array

Hi all ,

  I have array value as shown below, i have paste my test php code below:
I have problem when doing usort() when 'country' = '', i would like to display records where country = '' last. Any ideas how to do that ?

Thanks

   $arraytest= array(
      array
         (
             'country' => '',
         )
      ,
      array
         (
             'country' => 'Thailand',
         )
      ,
      array
         (
             'country' => 'Singapore',
         )
      ,
      array
         (
             'country' => 'Singapore',
         )
      ,
      array
         (
             'country' => '',
         )
       ,
          array
         (
             'country' => '',
         )
        ,
        array
         (
             'country' => '',
         )

      );


   function cmpcountry($a, $b)
   {

         $country1 = $a['country'];
         $country2 = $b['country'];

          return ($country1 < $country2) ? -1 : 1;
   }

     usort($arraytest,"cmpcountry");
     while(list($name,$value)=each($arraytest)){
           echo $name."<br><br>";

           while(list($n,$v) = each($arraytest[$name])){
               echo $v."<br><br>";
           }
      }


--- End Message ---
--- Begin Message ---
At 10:31 PM 7/30/2006, weetat wrote:
I have problem when doing usort() when 'country' = '', i would like to display records where country = '' last. Any ideas how to do that ?
...
  $arraytest= array(
     array
        (
            'country' => '',
        )
     ,
     array
        (
            'country' => 'Thailand',
        )
...
  function cmpcountry($a, $b)
  {
        $country1 = $a['country'];
        $country2 = $b['country'];

         return ($country1 < $country2) ? -1 : 1;
  }


Weetat,

You can sort the blank fields to the end simply by forcing their evaluated values in your usort callback function:

  function cmpcountry($a, $b)
  {
        $country1 = $a['country'];
        $country2 = $b['country'];

                if ($country1 == '') $country1 = "zzzzzzz";
                if ($country2 == '') $country2 = "zzzzzzz";

        return ($country1 < $country2) ? -1 : 1;
  }

...or, using ternary syntax:

  function cmpcountry($a, $b)
  {
        $country1 = ($a['country'] == '') ? "zzzzzzz" : $a['country'];
        $country2 = ($b['country'] == '') ? "zzzzzzz" : $b['country'];

        return ($country1 < $country2) ? -1 : 1;
  }


Regards,
Paul
--- End Message ---
--- Begin Message ---
At 05:40 PM 7/30/2006, Peter Lauri wrote:
   function cmpcountry($a, $b)
   {

         $country1 = $a['country'];
         $country2 = $b['country'];

           if($country1=='') return 1;
           else return ($country1 < $country2) ? -1 : 1;

   }


Good call, Peter; my suggestion was unnecessarily fat.

Weetat, both Peter's and my solutions do work -- see here:
http://juniperwebcraft.com/test/sortTest.php
source code:
http://juniperwebcraft.com/test/sortTest.txt

I could make that last statement just a bit simpler:

  function cmpcountry($a, $b)
  {
        $country1 = ($a['country'] == '') ? "zzzzzzz" : $a['country'];
        $country2 = ($b['country'] == '') ? "zzzzzzz" : $b['country'];

        return ($country1 > '' && $country1 < $country2) ? -1 : 1;
  }

I'm curious to know why none of this code works properly if it directly compares ($a['country'] < $b['country']). Why are the intermediate variables necessary?

Paul
--- End Message ---
--- Begin Message ---
At 12:22 AM 7/31/2006, Paul Novitski wrote:
I could make that last statement just a bit simpler:

  function cmpcountry($a, $b)
  {
        $country1 = ($a['country'] == '') ? "zzzzzzz" : $a['country'];
        $country2 = ($b['country'] == '') ? "zzzzzzz" : $b['country'];

        return ($country1 > '' && $country1 < $country2) ? -1 : 1;
  }


*Sigh* I shouldn't post this late at night. This is the comparison function that works for me:

  function cmpcountry($a, $b)
  {
        $country1 = ($a['country'] == '') ? "zzzzzzz" : $a['country'];
        $country2 = ($b['country'] == '') ? "zzzzzzz" : $b['country'];

        return ($country1 < $country2) ? -1 : 1;
  }

demo: http://juniperwebcraft.com/test/sortTest.php
code: http://juniperwebcraft.com/test/sortTest.txt

Paul
--- End Message ---
--- Begin Message ---

Hi ,

  Doesn't work .
  Any ideas ?

Thanks
Peter Lauri wrote:
   function cmpcountry($a, $b)
   {

         $country1 = $a['country'];
         $country2 = $b['country'];

           if($country1=='') return 1;
           else return ($country1 < $country2) ? -1 : 1;

   }

-----Original Message-----
From: weetat [mailto:[EMAIL PROTECTED] Sent: Monday, July 31, 2006 12:32 PM
To: [email protected]
Subject: [PHP] sorting in array

Hi all ,

  I have array value as shown below, i have paste my test php code below:
I have problem when doing usort() when 'country' = '', i would like to display records where country = '' last. Any ideas how to do that ?

Thanks

   $arraytest= array(
      array
         (
             'country' => '',
         )
      ,
      array
         (
             'country' => 'Thailand',
         )
      ,
      array
         (
             'country' => 'Singapore',
         )
      ,
      array
         (
             'country' => 'Singapore',
         )
      ,
      array
         (
             'country' => '',
         )
       ,
          array
         (
             'country' => '',
         )
        ,
        array
         (
             'country' => '',
         )

      );


   function cmpcountry($a, $b)
   {

         $country1 = $a['country'];
         $country2 = $b['country'];

          return ($country1 < $country2) ? -1 : 1;
   }

     usort($arraytest,"cmpcountry");
     while(list($name,$value)=each($arraytest)){
           echo $name."<br><br>";

           while(list($n,$v) = each($arraytest[$name])){
               echo $v."<br><br>";
           }
      }


--- End Message ---
--- Begin Message ---
Thanks Paul,

  Very weird tried Peter's option, it doesn't work.

  Btw , how to sort by ascending ?

Thanks

Paul Novitski wrote:
At 12:22 AM 7/31/2006, Paul Novitski wrote:
I could make that last statement just a bit simpler:

  function cmpcountry($a, $b)
  {
        $country1 = ($a['country'] == '') ? "zzzzzzz" : $a['country'];
        $country2 = ($b['country'] == '') ? "zzzzzzz" : $b['country'];

        return ($country1 > '' && $country1 < $country2) ? -1 : 1;
  }


*Sigh* I shouldn't post this late at night. This is the comparison function that works for me:

  function cmpcountry($a, $b)
  {
        $country1 = ($a['country'] == '') ? "zzzzzzz" : $a['country'];
        $country2 = ($b['country'] == '') ? "zzzzzzz" : $b['country'];

        return ($country1 < $country2) ? -1 : 1;
  }

demo: http://juniperwebcraft.com/test/sortTest.php
code: http://juniperwebcraft.com/test/sortTest.txt

Paul

--- End Message ---
--- Begin Message ---
Thanks Paul,

  Very weird tried Peter's option, it doesn't work.

  Btw , how to sort by ascending ?

Thanks

Paul Novitski wrote:
At 12:22 AM 7/31/2006, Paul Novitski wrote:
I could make that last statement just a bit simpler:

  function cmpcountry($a, $b)
  {
        $country1 = ($a['country'] == '') ? "zzzzzzz" : $a['country'];
        $country2 = ($b['country'] == '') ? "zzzzzzz" : $b['country'];

        return ($country1 > '' && $country1 < $country2) ? -1 : 1;
  }


*Sigh* I shouldn't post this late at night. This is the comparison function that works for me:

  function cmpcountry($a, $b)
  {
        $country1 = ($a['country'] == '') ? "zzzzzzz" : $a['country'];
        $country2 = ($b['country'] == '') ? "zzzzzzz" : $b['country'];

        return ($country1 < $country2) ? -1 : 1;
  }

demo: http://juniperwebcraft.com/test/sortTest.php
code: http://juniperwebcraft.com/test/sortTest.txt

Paul

--- End Message ---
--- Begin Message ---
At 01:14 AM 7/31/2006, weetat wrote:
Thanks Paul,

  Very weird tried Peter's option, it doesn't work.

  Btw , how to sort by ascending ?


Please explain what you mean. The current script DOES sort ascending by country (except for the blank country fields which are placed at the end):
http://juniperwebcraft.com/test/sortTest.php

Singapore, Singapore, Thailand is an ascending sort.

Your original code also sorted ascending by country, but with the blank countries at the front:

  function cmpcountry($a, $b)
  {
        $country1 = $a['country'];
        $country2 = $b['country'];

        return ($country1 < $country2) ? -1 : 1;
  }

Paul
--- End Message ---
--- Begin Message ---
And this for DESCending

   function cmpcountry($a, $b)
   {
         $country1 = $a['country'];
         $country2 = $b['country'];

                if($country1=='' OR $country2=='') {
                        if($country1==$country2) return 0;
                        elseif($country1=='') return 1;
                        else return -1;
                } else return ($country1 < $country2) ? 1 : -1;
   }

-----Original Message-----
From: weetat [mailto:[EMAIL PROTECTED] 
Sent: Monday, July 31, 2006 3:15 PM
To: [email protected]; Paul Novitski
Cc: [email protected]
Subject: Re: [PHP] sorting in array

Thanks Paul,

   Very weird tried Peter's option, it doesn't work.

   Btw , how to sort by ascending ?

Thanks

Paul Novitski wrote:
> At 12:22 AM 7/31/2006, Paul Novitski wrote:
>> I could make that last statement just a bit simpler:
>>
>>   function cmpcountry($a, $b)
>>   {
>>         $country1 = ($a['country'] == '') ? "zzzzzzz" : $a['country'];
>>         $country2 = ($b['country'] == '') ? "zzzzzzz" : $b['country'];
>>
>>         return ($country1 > '' && $country1 < $country2) ? -1 : 1;
>>   }
> 
> 
> *Sigh*  I shouldn't post this late at night.  This is the comparison 
> function that works for me:
> 
>   function cmpcountry($a, $b)
>   {
>         $country1 = ($a['country'] == '') ? "zzzzzzz" : $a['country'];
>         $country2 = ($b['country'] == '') ? "zzzzzzz" : $b['country'];
> 
>         return ($country1 < $country2) ? -1 : 1;
>   }
> 
> demo: http://juniperwebcraft.com/test/sortTest.php
> code: http://juniperwebcraft.com/test/sortTest.txt
> 
> Paul 

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

--- End Message ---
--- Begin Message ---
Sorry, I just woke up and just posted an reply without thinking, use this:

   function cmpcountry($a, $b)
   {
         $country1 = $a['country'];
         $country2 = $b['country'];

                if($country1=='' OR $country2=='') {
                        if($country1==$country2) return 0;
                        elseif($country1=='') return 1;
                        else return -1;
                } else return ($country1 < $country2) ? -1 : 1;
   }

/Peter



-----Original Message-----
From: Paul Novitski [mailto:[EMAIL PROTECTED] 
Sent: Monday, July 31, 2006 1:57 PM
To: [email protected]
Subject: Re: [PHP] sorting in array

At 10:31 PM 7/30/2006, weetat wrote:
>  I have problem when doing usort() when 'country' = '', i would 
> like to display records where country = '' last. Any ideas how to do that
?
...
>   $arraytest= array(
>      array
>         (
>             'country' => '',
>         )
>      ,
>      array
>         (
>             'country' => 'Thailand',
>         )
...
>   function cmpcountry($a, $b)
>   {
>         $country1 = $a['country'];
>         $country2 = $b['country'];
>
>          return ($country1 < $country2) ? -1 : 1;
>   }


Weetat,

You can sort the blank fields to the end simply by forcing their 
evaluated values in your usort callback function:

   function cmpcountry($a, $b)
   {
         $country1 = $a['country'];
         $country2 = $b['country'];

                 if ($country1 == '') $country1 = "zzzzzzz";
                 if ($country2 == '') $country2 = "zzzzzzz";

         return ($country1 < $country2) ? -1 : 1;
   }

...or, using ternary syntax:

   function cmpcountry($a, $b)
   {
         $country1 = ($a['country'] == '') ? "zzzzzzz" : $a['country'];
         $country2 = ($b['country'] == '') ? "zzzzzzz" : $b['country'];

         return ($country1 < $country2) ? -1 : 1;
   }


Regards,
Paul 

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

--- End Message ---
--- Begin Message ---
weetat wrote:
> Hi all ,
> 
>  I have array value as shown below, i have paste my test php code below:
>  I have problem when doing usort() when 'country' = '', i would like to
> display records where country = '' last. Any ideas how to do that ?
> ...

You might try searching the list's archive's.  This question has been
asked and answered several times before.

http://aspn.activestate.com/ASPN/Mail/Message/php-general/3172783
http://aspn.activestate.com/ASPN/Mail/Message/php-general/3199536
http://aspn.activestate.com/ASPN/Mail/Message/php-general/3212898

one of the solutions offered:
http://aspn.activestate.com/ASPN/Mail/Message/3172873

--- End Message ---
--- Begin Message ---
Have been wondering if this is possible....

Basically I have 3 posted arrays,
$_POST['reporton_company']  (this can be various company id's. ie 3,6,7)
$_POST['report_period'] (this can be various periods but a max of 4
submitted. ie 3,4,5)
$_POST['questions_groups'] (this can be various - starting from 1- whatever
(usually a max of 10 or 11). ie 1,2,3,4,5,6,7,8,9,10)

So the select should work as

1. for each company listed go through the loop
2. for each report period listed go through loop for each company
3. for each questions group go through the loop for each report period and
each company..

So I came up with this - will it work??


foreach($_POST['reporton_company'] as $cmp_ind =>$arrayd_cmp_id) {
        foreach($_POST['report_period'] as $rep_ind =>$arrayd_per_id) {
                foreach($_POST['questions_groups'] as $group_ind => 
$arrayd_group_no) {
                        mysql_select_db($database_name, $dname);

                        $query_get_list_of_answers = "SELECT * FROM answers 
LEFT JOIN (questions,
period) ON (questions.id=answers.ans_l_question_id                      AND
period.per_id=ans_l_period_id) where ans_l_company_id = '$arrayd_cmp_id' AND
per_id = '$arrayd_per_id' AND group_no =                        
'$arrayd_group_no';";

$get_list_of_answers = mysql_query($query_get_list_of_answers, $antiva) or
die(mysql_error());
$row_get_list_of_answers = mysql_fetch_assoc($get_list_of_answers);
$totalRows_get_list_of_answers = mysql_num_rows($get_list_of_answers);
                }

        }
}

Anyone suggest an easier way?

Cheers
Chris

--- End Message ---
--- Begin Message ---
foreach($_POST['reporton_company'] as $cmp_ind =>$arrayd_cmp_id) {
        foreach($_POST['report_period'] as $rep_ind =>$arrayd_per_id) {
                foreach($_POST['questions_groups'] as $group_ind => 
$arrayd_group_no) {
                        mysql_select_db($database_name, $dname);

Why do that here? That's going to do it for each element in the
arrays, lots of overhead!

Move that outside the first loop.

I'd probably leave it as it is and make sure your data is what you
expect, ie use mysql_real_escape_string in appropriate places.

You could clean up one loop by doing this:

$query_get_list_of_answers = "SELECT * FROM answers LEFT JOIN
(questions, period) ON (questions.id=answers.ans_l_question_id AND
period.per_id=ans_l_period_id) where ans_l_company_id =
'$arrayd_cmp_id' AND per_id = '$arrayd_per_id' AND group_no IN (" .
implode(',', $_POST['questions_groups']) . ")";

but if I can enter dodgy values in the questions_groups form field,
you're hosed.

--
Postgresql & php tutorials
http://www.designmagick.com/

--- End Message ---
--- Begin Message --- I am trying to debug a php script that I downloaded, which has a memory leak in it.

I was looking for a way to find what variables were in php's memory, and what size, they were, but I couldn't find anything?

The script is a off-line wiki conversion tool (walks through a wiki to create a bunch of html files for off line viewing). As the tools walks the files, and does the conversion, I can see the memory consumption go up and up as it walks the files, until it hits the mem limit, and crashes.

Any suggestions appreciated.

Thanks
-Robin

--- End Message ---
--- Begin Message ---
Robin Getz wrote:
> I am trying to debug a php script that I downloaded, which has a memory
> leak in it.
> 
> I was looking for a way to find what variables were in php's memory, and
> what size, they were, but I couldn't find anything?
> 
> The script is a off-line wiki conversion tool (walks through a wiki to
> create a bunch of html files for off line viewing). As the tools walks
> the files, and does the conversion, I can see the memory consumption go
> up and up as it walks the files, until it hits the mem limit, and crashes.
> 
> Any suggestions appreciated.
> 
> Thanks
> -Robin
> 

xdebug has some advanced tools to help you track down these kind of
problems.  I believe that there are also some other similar php
debugging extensions.


David

--- End Message ---
--- Begin Message ---
On 7/31/06, Robin Getz <[EMAIL PROTECTED]> wrote:
I am trying to debug a php script that I downloaded, which has a memory
leak in it.

I was looking for a way to find what variables were in php's memory, and
what size, they were, but I couldn't find anything?

The script is a off-line wiki conversion tool (walks through a wiki to
create a bunch of html files for off line viewing). As the tools walks the
files, and does the conversion, I can see the memory consumption go up and
up as it walks the files, until it hits the mem limit, and crashes.

Depending on how "big" the wiki is, if it's creating references to
other files it will need a lot of memory to remember all the different
links it has to create (phpdocumentor has a similar issue/reason).

--
Postgresql & php tutorials
http://www.designmagick.com/

--- End Message ---
--- Begin Message ---
Hi all,

I need to implement AES decryption algorythm on client side (in browser).
I tried javascript but it is too slow.
Does anybody have others ideas how to decrypt data transfered by from server to client in browser?
--- End Message ---
--- Begin Message ---
        Encrypting/decriptying data at client side (in javascript or whatever
script which sends the code to the client) is useless. It's like having
the data "in clear" at client side. I use JavaScript only to make the
interface "interactive".

        Andy

Andrew Senyshyn wrote:
> Hi all,
> 
> I need to implement AES decryption algorythm on client side (in browser).
> I tried javascript but it is too slow.
> Does anybody have others ideas how to decrypt data transfered by from
> server to client in browser?
> 

--- End Message ---
--- Begin Message ---
[snip]
I need to implement AES decryption algorythm on client side (in
browser).
I tried javascript but it is too slow.
Does anybody have others ideas how to decrypt data transfered by from 
server to client in browser?
[/snip]

You need to employ a Secure Sockets Layer.

--- End Message ---
--- Begin Message ---
What do you need exaclty?

Do you wanna encrypt the datas, that will be transfered to the client
Or
do you wanna encrypt the source code, that will be displayed on the client?

For reason 1 you can use SSL connection to encrypt the transfered datas.

For reason 2: forget it. The Browser needs to know the source code, so he can 
display it :) Except you use JS to tell the browser the correct HTML code :)

But as you said JS is slow, so not possible as far as i know :)

on Monday 31 July 2006 13:59, Andrew Senyshyn wrote:
> Hi all,
>
> I need to implement AES decryption algorythm on client side (in browser).
> I tried javascript but it is too slow.
> Does anybody have others ideas how to decrypt data transfered by from
> server to client in browser?

--- End Message ---
--- Begin Message ---
At 2:59 PM +0300 7/31/06, Andrew Senyshyn wrote:
I need to implement AES decryption algorythm on client side (in browser).
I tried javascript but it is too slow.
Does anybody have others ideas how to decrypt data transfered by from server to client in browser?

Excuse my ignorance, but if you send the client a coded message and the means to decode it -- what's the point of encrypting the message?

tedd
--
-------
http://sperling.com  http://ancientstones.com  http://earthstones.com

--- End Message ---
--- Begin Message ---
        Then get a SSL certificate and let the browser do the job. If you do it
with JavaScript or open-code language why shouldn't I just take your
code and sniff the data you/the browser sends and decrypt it.

        Andy

Andrew Senyshyn wrote:
> Andrei wrote:
>>     Encrypting/decriptying data at client side (in javascript or whatever
>> script which sends the code to the client) is useless. It's like having
>> the data "in clear" at client side. I use JavaScript only to make the
>> interface "interactive".
>>
>>     Andy
>>
>> Andrew Senyshyn wrote:
>>  
>>> Hi all,
>>>
>>> I need to implement AES decryption algorythm on client side (in
>>> browser).
>>> I tried javascript but it is too slow.
>>> Does anybody have others ideas how to decrypt data transfered by from
>>> server to client in browser?
>>>
>>>     
>>
>>   
> Ok. But when you propose to decrypt data?
> I have text in DB encrypted with AES. Get that text from DB with php. If
> I decrypt it in php, it will send text 'in clear' to client.
> I need encrypted data between server and client. only on client it must
> be decrypted.
> 
> 
> 

--- End Message ---
--- Begin Message ---
AES
http://csrc.nist.gov/CryptoToolkit/aes/
----
zerof

--- End Message ---
--- Begin Message ---
Andrei wrote:
        Then get a SSL certificate and let the browser do the job. If you do it
with JavaScript or open-code language why shouldn't I just take your
code and sniff the data you/the browser sends and decrypt it.
Just playing devil's advocate here...But I believe that if implemented properly, encryption/decryption on the client could be secure, for example a diffie-hellman key exchange with AJAX, followed by encryption.

jon

--- End Message ---
--- Begin Message ---
[snip]
Just playing devil's advocate here...But I believe that if implemented 
properly, encryption/decryption on the client could be secure, for 
example a diffie-hellman key exchange with AJAX, followed by encryption.
[/snip]

Doesn't matter the key, you must use SSL to encrypt from client to
server.

--- End Message ---
--- Begin Message ---
Jay Blanchard wrote:
[snip]
Just playing devil's advocate here...But I believe that if implemented properly, encryption/decryption on the client could be secure, for example a diffie-hellman key exchange with AJAX, followed by encryption.
[/snip]

Doesn't matter the key, you must use SSL to encrypt from client to
server.
Why *must* you use SSL? Again, devil's advocate here (SSL is probably much better) but that doesn't mean that you can't use some crazy JS and PHP to implement some alternative encryption technique. (Say a symmetric algorithm that isn't implemented in any standard SSL implementations, or a proof of concept etc.)

For example:
- Client (javascript) and Server (PHP script) decide on some key via secure key negotiation. - One end encrypts message using key and wacky encryption algorithm, other end decrypts it. Same thing again, client/server reversed.

SSL is obviously the recommended, trusted, proven, and accepted way of sending secure data, but there could potentially be cases where someone would want to try something else. It's not that it can't be done, it's more that there's no reason to do it that way. :-)

jon

--- End Message ---
--- Begin Message ---
[snip]
Why *must* you use SSL? Again, devil's advocate here (SSL is probably 
much better) but that doesn't mean that you can't use some crazy JS and 
PHP to implement some alternative encryption technique. (Say a symmetric

algorithm that isn't implemented in any standard SSL implementations, or

a proof of concept etc.)

For example:
- Client (javascript) and Server (PHP script) decide on some key via 
secure key negotiation.
- One end encrypts message using key and wacky encryption algorithm, 
other end decrypts it. Same thing again, client/server reversed.
[/snip]

This still leaves any Javascript exposed, doesn't it?

--- End Message ---
--- Begin Message ---
Jay Blanchard wrote:
This still leaves any Javascript exposed, doesn't it?
Yes, but that shouldn't matter. The algorithms for RSA, AES, etc, etc are all publicly available, why bother hiding their JavaScript implementations? Only the data would be encrypted.

jon

--- End Message ---
--- Begin Message ---
[snip]
Jay Blanchard wrote:
> This still leaves any Javascript exposed, doesn't it?
>   
Yes, but that shouldn't matter. The algorithms for RSA, AES, etc, etc 
are all publicly available, why bother hiding their JavaScript 
implementations? Only the data would be encrypted.
[/snip]

So, you're suggesting that you can use Ajax or some other mechanism to
hide the key on the server?

--- End Message ---
--- Begin Message ---
Jay Blanchard wrote:
This still leaves any Javascript exposed, doesn't it?

And OpenSSL is an open source security library..... does that make it insecure?

The fact the source is available is irrelevent if the proper key generation exchange/negotiation practices are adhered too.

I have to agree with Jon here (in both cases - that it is possible, but also that it is somewhat pointless when SSL is so easy to use).

Col.

--- End Message ---
--- Begin Message ---
 

> -----Original Message-----
> From: Jay Blanchard [mailto:[EMAIL PROTECTED] 
> Sent: Monday, July 31, 2006 10:38 AM
> To: Jon Anderson; [php] PHP General List
> Subject: RE: [PHP] AES client side
> 
> [snip]
> Why *must* you use SSL? Again, devil's advocate here (SSL is 
> probably much better) but that doesn't mean that you can't 
> use some crazy JS and PHP to implement some alternative 
> encryption technique. (Say a symmetric
> 
> algorithm that isn't implemented in any standard SSL 
> implementations, or
> 
> a proof of concept etc.)
> 
> For example:
> - Client (javascript) and Server (PHP script) decide on some 
> key via secure key negotiation.
> - One end encrypts message using key and wacky encryption 
> algorithm, other end decrypts it. Same thing again, 
> client/server reversed.
> [/snip]
> 
> This still leaves any Javascript exposed, doesn't it?

The algorithm may be exposed but the internal data may not be. If the
javascript, through AJAX or some other method, holds a 'private key'
internally you might be able to duplicate the public/private key
methodology of most encryption systems. This though essentially
duplicates the SSL layer, but does allow you to use other algorithms
which are similar but which may have different traits that you want to
work with, such as not requiring SSL, or being transparently encrypted
to the user. I wouldn't suggest it but it is POSSIBLE from a proof of
concept viewpoint and could, theoretically, have some usefulness.

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

--- End Message ---
--- Begin Message ---
Jay Blanchard wrote:
Yes, but that shouldn't matter. The algorithms for RSA, AES, etc, etc are all publicly available, why bother hiding their JavaScript implementations? Only the data would be encrypted.
[/snip]

So, you're suggesting that you can use Ajax or some other mechanism to
hide the key on the server?
There's no "hiding". You could use a secure key exchange mechanism, such as Diffie-Hellman.

Diffie-Hellman is used to generate a shared key between two hosts (say "A" and "B") such that each host knows the key, but any third party listening in on the information is unable to trivially reconstruct the key.

See: http://en.wikipedia.org/wiki/Diffie-Hellman

jon

--- End Message ---
--- Begin Message ---
[snip]
There's no "hiding". You could use a secure key exchange mechanism, such

as Diffie-Hellman.

Diffie-Hellman is used to generate a shared key between two hosts (say 
"A" and "B") such that each host knows the key, but any third party 
listening in on the information is unable to trivially reconstruct the
key.

See: http://en.wikipedia.org/wiki/Diffie-Hellman
[/snip]

I am quite familiar with diffie-helman and have used it extensively with
PGP and can see how it would be used like this, but isn't this a munged
fix as opposed to using SSL?

--- End Message ---
--- Begin Message ---
Jay Blanchard wrote:
I am quite familiar with diffie-helman and have used it extensively with
PGP and can see how it would be used like this, but isn't this a munged
fix as opposed to using SSL?
Yep. :-)

There are cases (testing new algorithms, proof of concept, something I haven't thought of, etc.) where you either can't or might not want to use SSL. Though as myself and others have said, SSL should clearly be the preferred option. The question isn't whether it should be done, but whether it could. ;-)

jon

--- End Message ---
--- Begin Message ---
On 31/07/06, Jon Anderson <[EMAIL PROTECTED]> wrote:
Jay Blanchard wrote:
> Yes, but that shouldn't matter. The algorithms for RSA, AES, etc, etc
> are all publicly available, why bother hiding their JavaScript
> implementations? Only the data would be encrypted.
> [/snip]
>
> So, you're suggesting that you can use Ajax or some other mechanism to
> hide the key on the server?
>
There's no "hiding". You could use a secure key exchange mechanism, such
as Diffie-Hellman.

Diffie-Hellman is used to generate a shared key between two hosts (say
"A" and "B") such that each host knows the key, but any third party
listening in on the information is unable to trivially reconstruct the key.

See: http://en.wikipedia.org/wiki/Diffie-Hellman

How about if the third party can control one side of the transaction
by altering the javascript that implements it while in transit -  for
instance by adding a couple of lines that transmit the key to the
third party after the key exchange?

-robin

--- End Message ---
--- Begin Message ---
Robin Vickery wrote:
How about if the third party can control one side of the transaction
by altering the javascript that implements it while in transit -  for
instance by adding a couple of lines that transmit the key to the
third party after the key exchange?
If the algorithm written in JavaScript is both trusted and installed beforehand (like SSL libs)....

You're right though. Without having some trust mechanism, the whole thing could collapse. In fact, if you're using Diffie-Hellman, and have a third party in the middle that is capable of altering data, they don't even have to alter the code. They can simply use the man-in-the-middle attack, and I don't think anyone would bother writing certificate handling functions in JavaScript to authenticate each party. :-)

jon

--- End Message ---
--- Begin Message ---
Any insights or tips into this?

httpd: Syntax error on line 232 of /home/www/conf/httpd.conf: Cannot load /home/www/modules/libphp5.so into server: /home/www/modules/libphp5.so: undefined symbol: _pcre_ucp_findprop

TIA.
-Brad

--- End Message ---
--- Begin Message ---
Utedd wrote:
Hi gang:

 From another list, a person posted:

"I want to use PHP's mb_substr() function to grab the first letter of a
UTF-8 encoded word (in Czech) being pulled out of MySQL. If I use the plain substr()
the data gets garbled and I get a ? symbol in the browser.

My host says
that in order to get multibyte string functions I'd have to compile my own
copy of PHP. That's getting a little deeper than I want to for one function
on one page. Does anyone know what I could do as a workaround?"

I've tried to help, but it appears beyond me.

Anyone have any advice I could pass on?

Thanks.

tedd

UTF8_decode() it first

--- End Message ---

Reply via email to