|
1 | | -phpCrypt 0.3.2 |
| 1 | +phpCrypt 0.4 |
2 | 2 | Ryan Gilfether |
3 | 3 | http://www.gilfether.com/phpcrypt |
4 | 4 |
|
5 | 5 |
|
6 | 6 | About |
7 | 7 | ============= |
8 | | -phpCrypt is an Open Source PHP Encryption library that does not require |
9 | | -or use the mCrypt or any other PHP extension. It's not as fast |
10 | | -as PHP's mCrypt extention, however if you are in a situation where you |
11 | | -can not use the mCrypt library, phpCrypt is a suitable alternative. |
| 8 | +phpCrypt is an encryption library written in PHP from scratch. It aims to |
| 9 | +implement all major encryption ciphers, modes, and other tools used for |
| 10 | +encryption and decryption. phpCrypt does not rely on mCrypt, other PHP |
| 11 | +extenions, or PEAR libraries. |
12 | 12 |
|
13 | | -This version of phpCrypt requires PHP 5.3 or later. |
| 13 | +It currently support many popular encryption ciphers. In addition it |
| 14 | +supports many popular modes of encryption. There are also tools to implement |
| 15 | +the different padding schemes, as well as multiple methods of creating an |
| 16 | +Initialization Vecotor (IV) for modes that require one. |
14 | 17 |
|
15 | | -Please visit phpCrypt's website for a list of options and constants |
16 | | -used in phpCrypt. phpCrypt's website also lists the required key |
17 | | -sizes for Ciphers, as well as which Modes work with which Ciphers. |
18 | | -http://www.gilfether.com/phpcrypt |
19 | | - |
20 | | -All Cipher algorithms were implemented using freely available resources |
21 | | -found online and in books. |
| 18 | +phpCrypt is developed by Ryan Gilfether <http://www.gilfether.com/phpcrypt> |
22 | 19 |
|
23 | 20 |
|
24 | 21 | Documentation |
25 | 22 | ============= |
26 | | -Visit the phpCrypt website at http://www.gilfether.com/phpcrypt. Also, |
27 | | -the 'examples' directory has demo code of phpCrypt in use. Below is an |
28 | | -example of encrypting a string. |
| 23 | +The phpCrypt website at http://www.gilfether.com/phpcrypt lists much of the |
| 24 | +information you need to begin. The phpCrypt website lists all the constants |
| 25 | +you need to select ciphers, modes, padding, and IV methods. In addition, |
| 26 | +phpCrypt comes with an `examples` directory which has sample code to help get |
| 27 | +you started. |
| 28 | + |
| 29 | +Using phpCrypt is easy to use. An example of encrypting a string using AES-128 |
| 30 | +with CTR mode is demonstrated below: |
| 31 | + |
| 32 | + <?php |
| 33 | + include("/path/to/phpcrypt/phpCrypt.php"); |
| 34 | + use PHP_Crypt\PHP_Crypt as PHP_Crypt; |
| 35 | + |
| 36 | + $data = "This is my secret message."; |
| 37 | + $key = "MySecretKey01234"; |
| 38 | + $crypt = new PHP_Crypt($key, PHP_Crypt::CIPHER_AES_128, PHP_Crypt::MODE_CTR); |
| 39 | + |
| 40 | + $iv = $crypt->createIV(); |
| 41 | + $encrypt = $crypt->encrypt($data); |
| 42 | + |
| 43 | + $crypt->IV($iv); |
| 44 | + $decrypt = $crypt->decrypt($encrypt); |
| 45 | + ?> |
| 46 | + |
| 47 | + |
| 48 | +Generating Random Numbers on Windows |
| 49 | +==================================== |
| 50 | + |
| 51 | +By default phpCrypt will use the PHP mt_rand() random number generator on |
| 52 | +Windows to create an IV. You have the option to use the random number generator |
| 53 | +found in the Microsoft CAPICOM SDK which is more secure. |
| 54 | + |
| 55 | +Before this will work you must install the Microsoft CAPICOM SDK and enable the |
| 56 | +PHP com_dotnet extension: |
| 57 | + |
| 58 | + * Download CAPICOM from Microsoft at |
| 59 | + http://www.microsoft.com/en-us/download/details.aspx?id=25281 |
| 60 | + |
| 61 | + * Double click the MSI file you downloaded, and follow the install directions |
| 62 | + |
| 63 | + * Open a command prompt and register the DLL: |
| 64 | + regsvr32 C:\Program Files\PATH TO\CAPICOM SDK\Lib\X86\capicom.dll |
29 | 65 |
|
30 | | -<?php |
31 | | -include("/path/to/phpcrypt/phpCrypt.php"); |
32 | | -use PHP_Crypt\PHP_Crypt as PHP_Crypt; |
| 66 | + * Now edit php.ini to enable the com_dotnet extension: |
| 67 | + extension=php_com_dotnet.dll |
33 | 68 |
|
34 | | -$data = "This is my secret message."; |
35 | | -$key = "MySecretKey01234"; |
36 | | -$crypt = new PHP_Crypt($key, PHP_Crypt::CIPHER_AES_128, PHP_Crypt::MODE_CTR); |
| 69 | + * If you are running PHP as an Apache module, restart Apache. |
37 | 70 |
|
38 | | -$iv = $crypt->createIV(); |
39 | | -$encrypt = $crypt->encrypt($data); |
| 71 | +To use the Windows random number generator in CAPICOM you would call creatIV() like so: |
40 | 72 |
|
41 | | -$crypt->IV($iv); |
42 | | -$decrypt = $crypt->decrypt($encrypt); |
43 | | -?> |
| 73 | + $iv = $crypt->createIV(PHP_Crypt::IV_WIN_COM); |
44 | 74 |
|
45 | 75 |
|
46 | 76 | GPL Stuff |
|
0 commit comments