Using phpseclib with Yii

You are viewing revision #4 of this wiki article.
This version may not be up to date with the latest version.
You may want to view the differences to the latest version.

next (#5) »

I installed phpseclib because I needed to do some AES encryption in my project. After all the hassle of installing php lib, I found out that Yii already has a security module (securityManager). I finally decided to keep using phpseclib because it has one big advantage over Yii securityManager module, it does not requite mcrypt to be installed in the phpserver!

Installing phpseclib is not as straightforward as you could imagine. Yii lazy loading (I think it is called like that) is not compatible with phpseclib files because classes are not called the same as the file names they are in.

-Steps to install phpseclib-

(written on 2/Oct/2012, using Yii version 1.1.12. and phpseclib 0.3.0)

1) download phpseclib from:

2) uncompress the downloaded archive, rename the folder to "phpseclib", and put it into your /vendors project directory.

3) rename all the files under /vendors/phpseclib/Crypt like this:

AES.php -> Crypt_AES.php

DES.php -> Crypt_DES.php

etc... (just prepend "Crypt_" in the file name)

4) search for "require_once" commands in those files and change them so they point to the new file names.

For example, in Crypt_AES.php change:

if (!class_exists('Crypt_Rijndael')) {
    require_once 'Rijndael.php';


if (!class_exists('Crypt_Rijndael')) {
    require_once 'Crypt_Rijndael.php';

5) in config/main include phplib:


6) now you can use phplib in your project. For example within a model you can use:

public function encrypt($text){
  $cipher = new Crypt_AES();
  return bin2hex($cipher->encrypt($text));

(see phplib documentation for more details)

0 0
Viewed: 18 283 times
Version: Unknown (update)
Category: How-tos
Tags: security
Written by: nkd
Last updated by: nkd
Created on: Oct 2, 2012
Last updated: 10 years ago
Update Article


View all history

Related Articles