T-Encryption is a single file simple encryption class for PHP
If you use this encryption class, you can encrypt such as
- String
- File (Image, PDF)
I coded this encryption classes because so many a news about Indonesian government's data are stolen by hackers and leak to the internet. I hope you enjoy this class. coded with love by Teguh Rijanandi for everyone and if you see any error or bug you can feel free to open new issue or you can collaborate with me use pull request. Thanks
Note :
- WE NEVER STORE ANY DATA / FILE FROM YOU
- T means is Teguh (from my first letter name)
Before we start, please keep master password in encrypt and decrypt step are same and if the master password are not same, the decrypt process results is null like this
- Download this repository
- Copy t_encrypt.php file to what do you want to store, for example your root project folder
- Import php file use
require_once 't_encrypt.php';
- Please see sample code below
<?php
// import class
require_once 't_encrypt.php';
// please change this password with your own password
// and make sure it is not too short, and please keep it secret
$masterpassword = "beautiful_system";
return t_encrypt::setPassword($masterpassword)
// You can set input as string
->input('mendoan')
// and you can print as string (PHP echo)
->print();
// Results
// zyMXBNOlXqJnJohyfB1/ctdICm9weM4T4Ch3bgf5fnsIeJci4FzFeUtbEa0ZODSL54rhH39QP5Z9uW33NPO3bcVv/XiyjVljxIbp8o3P2UI=
Encrypt uploaded file and show the encryted string
<?php
require_once 't_encrypt.php';
$masterpassword = "beautiful_system";
return t_encrypt::setPassword($masterpassword)
->input($_FILES['file'])
->print();
in this section i was upload a file an this the results
Encrypt file use a path and show the encryted string
<?php
require_once 't_encrypt.php';
$masterpassword = "beautiful_system";
return t_encrypt::setPassword($masterpassword)
->input("/Users/mymac/Downloads/DSC_0301a.jpeg")
->print();
and when i fetch use postman, you can see the results here
<?php
// import the package
require_once 't_encrypt.php';
// please change this password with your own password
// and make sure it is not too short, and please keep it secret
// AND PLEASE MAKE SURE THIS PASSWORD IS THE SAME WITH THE PASSWORD IN
// encrypt_sample.php
$masterpassword = "beautiful_system";
// decrypt sample
return t_encrypt::setPassword($masterpassword)
->encrypted_string("M7J1nJ3i3o2pP5rBvvDVBtTTi4kqPbpmrpmNUWf5FtVi1gLULg8y4jqCvmniabpnmR1izphuXCEo/fgUtIgMmKZ9+O0aW6ev8Jff9SOwGkA=") // mendoan
// and you can print as string (PHP echo, image stream or pdf stream)
->print();
In this section we want to try decrypt a hashed text from a txt file
<?php
require_once 't_encrypt.php';
$masterpassword = "beautiful_system";
return t_encrypt::setPassword($masterpassword)
->encrypted_string(__DIR__ . "/example/encrypted_string.txt")
->print();
// Results :
// mendoan
You can set a master password for encryption and decryption proccess use ::setPassword function like this
$t_encrypt = t_encrypt::setPassword($masterpassword)
Note : You must choose only one encryption and decryption function
- You can set input as string use this function
$t_encrypt = $t_encrypt->input('mendoan')
- You can set input as POST file use
$t_encrypt = $t_encrypt->input($_FILES['file'])
- Or you can set input as file path use
$t_encrypt = $t_encrypt->input("/Users/mymac/Downloads/Resume_Teguh Rijanandi.docx.pdf")
- You can print output as string (PHP echo) use
$t_encrypt = $t_encrypt->print();
- You can return the string (PHP Return) use
$t_encrypt = $t_encrypt->show();
- or you can save as file use you can type for your files extension here but we prefer to save as txt file
$t_encrypt = $t_encrypt->saveAsFile(__DIR__ . "/example/encrypted_pdf.txt");
- You can put encrypted string like this
$t_encrypt = $t_encrypt->encrypted_string("M7J1nJ3i3o2pP5rBvvDVBtTTi4kqPbpmrpmNUWf5FtVi1gLULg8y4jqCvmniabpnmR1izphuXCEo/fgUtIgMmKZ9+O0aW6ev8Jff9SOwGkA=") // mendoan
- or you can put encrypted file here
$t_encrypt = $t_encrypt->encrypted_string(__DIR__ . "/example/encrypted_image.txt")
- You can print as string (PHP echo, image stream or pdf stream) use
$t_encrypt = $t_encrypt->print();
for example i was stream a pdf file in postman
and stream a image file in postman
- You can return the string (PHP Return) use
$t_encrypt = $t_encrypt->show();
for example i will show to you a base64 image code in a postman
- or you can save as file use you can type for your files extension here
$t_encrypt = $t_encrypt->saveAsFile(__DIR__ . "/example/decrypted_image.jpg");
// or
$t_encrypt = $t_encrypt->saveAsFile(__DIR__ . "/example/decrypted_text.txt");
For other code sample, you can read in encrypt_sample.php and decrypt_sample.php in this repository. And you can see encrypted and decrypted file in example folder. Thanks
If you want to collaborate my project or you see a bug or error please contact me via email or my linkedin, so i will fix immediatly