note 77153 added to function.mdecrypt-generic
| From: | Silvan at osu1 dot php dot net | Date: | Fri, 17 Aug 2007 07:34:42 +0000 |
| Subject: | note 77153 added to function.mdecrypt-generic | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-129552@lists.php.net to get a copy of this message | ||
It is generally not recommended to just use rtrim to remove the padding.
Use rtrim($str, "\0") for strings that do not end in "\0" or store the data
length during encryption.
(Although data containing "\0" sometimes gets corrupted during encryption so these types
of data actually should be packed.)
For example:
<?php
function encrypt($original_data)
{
$length = strlen($original_data);
$data_to_encrypt = $length.'|'.$original_data;
// Encrypt the data including its length.
// Do not save the length unencrypted, as this could be a (minor) security risk
}
function decrypt($cypher)
{
// Decrypt the cypher data first
// Next retrieve the original data
list($length, $padded_data) = explode('|', $decrypted_data, 2);
$original_data = substr($padded_data, 0, $length);
}
?>
----
Server IP: 69.147.83.197
Probable Submitter: 62.58.77.197
----
Manual Page -- http://www.php.net/manual/en/function.mdecrypt-generic.php
Edit -- https://master.php.net/note/edit/77153
Del: integrated -- https://master.php.net/note/delete/77153/integrated
Del: useless -- https://master.php.net/note/delete/77153/useless
Del: bad code -- https://master.php.net/note/delete/77153/bad+code
Del: spam -- https://master.php.net/note/delete/77153/spam
Del: non-english -- https://master.php.net/note/delete/77153/non-english
Del: in docs -- https://master.php.net/note/delete/77153/in+docs
Del: other reasons-- https://master.php.net/note/delete/77153
Reject -- https://master.php.net/note/reject/77153
Search -- https://master.php.net/manage/user-notes.php