update page now
Longhorn PHP 2026 - Call For Papers

Voting

: max(four, four)?
(Example: nine)

The Note You're Voting On

P.Peyremorte
10 years ago
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;
}
?>

<< Back to user notes page

To Top