PHP Classes

PHP Encryption Functions: Encrypt and decrypt files using mcrypt or OpenSSL

Recommend this page to a friend!
  Info   View files Example   View files View files (6)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 177 All time: 8,743 This week: 571Up
Version License PHP version Categories
encryptions 1.0.0The PHP License5PHP 5, Cryptography
Description 

Author

This class can encrypt and decrypt files using mcrypt or OpenSSL.

It provides static functions that can take a given string and encrypts its contents.

The class can also encrypt files in a given directory and store the encrypted version of the files in a given target directory.

The class can also decrypt data of a file that was previously encrypted by the class.

The class can use either the PHP functiions of mcrypt or openssl if extension mcrypt is not installed.

Picture of SzpaQ
  Performance   Level  
Name: SzpaQ <contact>
Classes: 5 packages by
Country: Poland Poland
Age: ???
All time rank: 302571 in Poland Poland
Week rank: 106 Up5 in Poland Poland Up

Example

<?php

error_reporting
(E_ALL);

ini_set('display_errors', 'On');






/*
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 * Copyright 2017 ?ukasz Szpak <szpaaaaq@gmail.com>
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 * ALL RIGHT RESERVED ?ukasz Szpak
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 * THIS FILE IS PART OF PROJECT SHOPINGBOOK
 *
 *
 *
 *
 *
 *
 *
 *
 *
 * Unauthorized copying of this file, via any medium is strictly prohibited
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 */

$newline = php_sapi_name() == "cli" ? PHP_EOL : '<br>';

require
'Crypter.php';

echo
'PHASE ONE: STRING' . $newline;

$string = 'TEXTTOENCRYPT';

$key = 'hash';

echo
'KEY FILE: hash'.$newline;

// PHASE 1 string

// encrypt string
$encrypted = Crypter::encrypt($string, $key);

// decrypt encrypted string
$decrypted = Crypter::decrypt($encrypted, $key);

echo
'STRING: ';
echo
$string . $newline;

echo
'ENCRYPTED STRING: ';
echo
$encrypted . $newline;

echo
'DECRYPTED STRING: ';
echo
$decrypted . $newline;

ECHO
$newline.$newline;

echo
'PHASE TWO: FILES' . $newline;

$source = __DIR__ .'/files';

$targetencrypted = 'files/encrypted';

$targetdecrypted = 'files/decrypted';

echo
'SOURCE DIRECTORY: '.$source .$newline;

echo
'ENCRYPTED DIRECTORY: '.$targetencrypted .$newline;

echo
'DECRYPTED DIRECTORY: '.$targetdecrypted .$newline;

echo
Crypter::encryptDirectory($source, $targetencrypted, $key);

// save encrypted file to files directory
file_put_contents($targetencrypted .'/encrypted_string', $encrypted);

echo
Crypter::decryptDirectory($targetencrypted, $targetdecrypted , $key);

echo
Crypter::encryptFile('README.md', 'hash');


Details

Check tests.php to see how to use it


  Files folder image Files  
File Role Description
Files folder imagefiles (3 files)
Plain text file Crypter.php Class Class source
Accessible without login Plain text file README.md Data Auxiliary data
Accessible without login Plain text file tests.php Example Example script

  Files folder image Files  /  files  
File Role Description
  Accessible without login Image file Cute-Dark-Cat-Wall...apersbrowse.com.jpg Data Auxiliary data
  Accessible without login Plain text file drawing.svg Data Auxiliary data
  Accessible without login Image file hash Data Auxiliary data

 Version Control Unique User Downloads Download Rankings  
 100%
Total:177
This week:0
All time:8,743
This week:571Up