Skip to content
forked from o/crypt-php

Library for encrypting and decrypting data with symmetric encryption

Notifications You must be signed in to change notification settings

Omgan/crypt-php

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 

Repository files navigation

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.

About

Library for encrypting and decrypting data with symmetric encryption

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • PHP 100.0%