forked from martins-pudelis/php-file-crypt
/
example.php
34 lines (27 loc) · 948 Bytes
/
example.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<?php
require 'FileCrypt.php';
$options = array(
'salt' => '@#@$#@RSDFSDF%$W%$TER^%YUTRYUUUUUUUUUUUU^&RTRTgfdgfdfgdfg^',
'cryptFilterName' => 'mcrypt.rijndael-256',
'decryptFilterName' => 'mdecrypt.rijndael-256',
'password' => ''
);
$src = __DIR__ . '/test/files/test.txt';
$targetEncrypted = __DIR__ . '/test/files/tmp/test.crypt';
$targetDecrypted = __DIR__ . '/test/files/tmp/test.txt';
$crypt = new FileCrypt($options);
$crypt
->setSourceFilePath($src)
->setTargetFilePath($targetEncrypted)
->encryptFile();
$crypt->setSourceFilePath($targetEncrypted)
->setTargetFilePath($targetDecrypted)
->decryptFile();
$sourceChecksum = md5_file($src);
$targetEncryptedChecksum = md5_file($targetEncrypted);
$targetDecryptedChecksum = md5_file($targetDecrypted);
if ($sourceChecksum == $targetDecryptedChecksum) {
echo 'Checksum matched';
} else {
echo 'Something went wrong, files checksum\'s differs';
}