note 119004 added to function.openssl-private-encrypt

From: Date: Tue, 15 Mar 2016 18:17:53 +0000
Subject: note 119004 added to function.openssl-private-encrypt
Groups: php.notes 
Request: Send a blank email to php-notes+get-205170@lists.php.net to get a copy of this message
A trick not mentioned in manual to know : - openssl_private_encrypt can encrypt a maximum of 117 chars at one time. - the encrypted output string is always 129 char length. If you use base64_encode on the encrypted output, it will give always 172 chars, with the last always "=" (filler). So, to encode a longer stream input you have to use something like : <?php $RawData = ... ; //Your input data to encode $PartialData = ''; $EncodedData = ''; $Split = str_split($RawData , 117); ForEach($Split as $Part) { openssl_private_encrypt($Part, $PartialData, $PrivateKey); $EncodedData .= base64_encode($PartialData); } ?> and then, to decode : <?php $OriginalData = ''; $Split = str_split($EncodedData , 172); ForEach($Split as $Part) { openssl_private_decrypt(base64_decode($Part), $PartialData, $PublicKey); $OriginalData .= $PartialData; } ?> ---- Server IP: 72.52.91.14 Probable Submitter: 78.197.168.132 ---- Manual Page -- http://php.net/manual/en/function.openssl-private-encrypt.php Edit -- https://master.php.net/note/edit/119004 Del: integrated -- https://master.php.net/note/delete/119004/integrated Del: useless -- https://master.php.net/note/delete/119004/useless Del: bad code -- https://master.php.net/note/delete/119004/bad+code Del: spam -- https://master.php.net/note/delete/119004/spam Del: non-english -- https://master.php.net/note/delete/119004/non-english Del: in docs -- https://master.php.net/note/delete/119004/in+docs Del: other reasons-- https://master.php.net/note/delete/119004 Reject -- https://master.php.net/note/reject/119004 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#205170) next »