https://github.com/o/crypt-php
Library for encrypting and decrypting data with symmetric encryption
https://github.com/o/crypt-php
Last synced: 8 months ago
JSON representation
Library for encrypting and decrypting data with symmetric encryption
- Host: GitHub
- URL: https://github.com/o/crypt-php
- Owner: o
- Created: 2010-11-23T12:26:30.000Z (over 15 years ago)
- Default Branch: master
- Last Pushed: 2018-07-18T23:44:34.000Z (almost 8 years ago)
- Last Synced: 2025-03-06T00:01:55.637Z (over 1 year ago)
- Language: PHP
- Homepage:
- Size: 6.84 KB
- Stars: 63
- Watchers: 10
- Forks: 19
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Introduction
------------
crypt-php is class for encrypting and decrypting any data type in PHP. It uses libmcrypt and rjindael-192 (also known as AES192) algorithm. It tested on Mac OS X server and some (Ubuntu and Centos) Linux distributions.
How to use
----------
Include Crypt.php to your PHP project and call Crypt class with new operator. It checks your environment is mcrypt installed correctly.
Encryption
==========
$crypt = new Crypt;
Now provide a secret key for encrypting and decrypting given data. This secret key must 8 character at least.
$crypt->setKey('eff99cfe6876008c6a6e080e4a382be1');
Ok, if you think encrypt a complex data type like an array or object we must declare this. (This parameter is not required for scalar data types like string and numbers)
$crypt->setComplexTypes(TRUE);
Now, we give data for encrypting.
$crypt->setData(array('username' => 'osmanungur', 'realname' => 'Osman Üngür', 'password' => 12345, 'groups' => array(18, 34)));
And finally we will encrypt it !
$encrypted = $crypt->encrypt();
// It gives you like cryptPHP#GjHTQ1SU+WWKb/CYhjyQrKOlXvsyIkqP#xuA6
S6NIQegeZtPjuuS9m3iy4F6yGw9cFBYIcYddJ7Y4g3lmFUObfRH3glx0Jv9ruOA9ZFx
4p4V1Lyyb+ikmEK84z8AEFPqaRhavJ7TUACAyVRfP6mcRbnKNW8awYoaHBD23q6/jCS
AvHXGAGBbXuVTk7yCIz3m9YnFzq3TG36edwIzDlG7L#9dbbfefa3e85c28c4b434505
7e472a6325ccfe02
This cipher is change on every request.
Decryption
==========
$crypt = new Crypt;
Do you remember ? We encrypted a complex data type.
$crypt->setComplexTypes(TRUE);
We set key for decryption. Dont forgot your key !
$crypt->setKey('eff99cfe6876008c6a6e080e4a382be1');
Now we will call encrypted data. Maybe it living in SQL or cookie.
$crypt->setData('cryptPHP#GjHTQ1SU+WWKb/CYhjyQrKOlXvsyIkqP#xuA6S6NI
QegeZtPjuuS9m3iy4F6yGw9cFBYIcYddJ7Y4g3lmFUObfRH3glx0Jv9ruOA9ZFx4p4V
1Lyyb+ikmEK84z8AEFPqaRhavJ7TUACAyVRfP6mcRbnKNW8awYoaHBD23q6/jCSAvHX
GAGBbXuVTk7yCIz3m9YnFzq3TG36edwIzDlG7L#9dbbfefa3e85c28c4b4345057e47
2a6325ccfe02');
Decrypting...
$decrypted = $crypt->decrypt();
Ok, now we discovering on our decrypted data.
var_dump($decrypted);
array
'username' => string 'osmanungur' (length=10)
'realname' => string 'Osman Üngür' (length=13)
'password' => int 12345
'groups' =>
array
0 => int 18
1 => int 34
Everything is ok ? If something went wrong please tell me whats going on from Issues page.