Ejemplo n.º 1
0
//       along with this program.  If not, see <http://www.gnu.org/licenses/>.
echo nl2br("Starts AES-file encryption" . "\n");
echo nl2br("==========================" . "\n");
require 'class.aesCrypt.php';
// class
$passphrase = 'ThisIsMySecretPassphrase';
// Initializing the class
$crypt = new AESCrypt($passphrase);
// Setting date and time
$date = date("Y-m-d");
echo nl2br("Date: " . $date . "\n");
$time = date("H:i:s");
echo nl2br("Time: " . $time . "\n");
// Adding date and time to the header
// of the encrypted file
$crypt->setExtText(array($crypt::CREATED_DATE => $date, $crypt::CREATED_TIME => $time));
// File to encrypt
//$file = 'path/to/my/file/file.txt';
$file = 'readme.txt';
echo nl2br("Encryption of the file: " . $file . "\n");
// read content
$data = file_get_contents($file);
// encrypt and write to a new file  (existing file is overwritten)
file_put_contents($file . '.aes', $crypt->encrypt($data));
echo nl2br("AES-file encryption finished" . "\n");
echo nl2br("============================" . "\n");
echo nl2br("AES-file decryption starts" . "\n");
echo nl2br("============================" . "\n");
echo nl2br("Decryption of: " . $file . '.aes' . "\n");
// read content
$data = file_get_contents($file . '.aes');