Code Monkey home page Code Monkey logo

crypt-php's Introduction

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.

crypt-php's People

Contributors

o avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.