note 56449 added to function.openssl-public-encrypt

From: Date: Fri, 02 Sep 2005 21:53:35 +0000
Subject: note 56449 added to function.openssl-public-encrypt
Groups: php.notes 
Request: Send a blank email to php-notes+get-94675@lists.php.net to get a copy of this message
T. Horsten explained the size limits on raw encryption. Here are two functions to encrypt/decrypt larger data when you can't use the envelope functions: function ssl_encrypt($source,$type,$key){ //Assumes 1024 bit key and encrypts in chunks. $maxlength=117; $output=''; while($source){ $input= substr($source,0,$maxlength); $source=substr($source,$maxlength); if($type=='private'){ $ok= openssl_private_encrypt($input,$encrypted,$key); }else{ $ok= openssl_public_encrypt($input,$encrypted,$key); } $output.=$encrypted; } return $output; } function ssl_decrypt($source,$type,$key){ // The raw PHP decryption functions appear to work // on 128 Byte chunks. So this decrypts long text // encrypted with ssl_encrypt(). $maxlength=128; $output=''; while($source){ $input= substr($source,0,$maxlength); $source=substr($source,$maxlength); if($type=='private'){ $ok= openssl_private_decrypt($input,$out,$key); }else{ $ok= openssl_public_decrypt($input,$out,$key); } $output.=$out; } return $output; } ---- Manual Page -- http://www.php.net/manual/en/function.openssl-public-encrypt.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+56449 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+56449&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+56449&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+56449&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+56449&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+56449&report=yes&reason=non-english Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+56449&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+56449&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#94675) next »