menu

Codeigniter Encrypt Class Library


Codeigniter Encrypt Class Library – This library provides various functions that are used to encription of data. $this->load->library(‘encrypt’); is used to load the library. Here in this tutorial, we are going to explain how to use encrypt class library.


Codeigniter encrypt class library | Load | Example

Let us understand how encrypt class works in codeigniter with examples.

Load encrypt library

First load encrpt library to use its functions, this library can be loaded simply as below-

How to load encrypt class library:

Functions:-

There are following functions available in encrypt class library.

  • 1. Encode
  • 2. Decode
  • 3. Set cipher
  • 4. Set mode

1. Encode

This function performs data enryption and returns string :-

  • Parameters :
  • $string (string) : Data to encrypt.
  • $key (string) : Encryption key.
  • Returns : Encrypted string.
  • Return type : string.

EXAMPLE

Lets see the simple example of encode.

Example of encode library:-

Codeigniter Encrypt Class Library

2. Decode

Decode function is used to decrypt an encoded data :-

  • Parameters :
  • $string (string) : String to decrypt.
  • $key (string) : Encryption key.
  • Returns : Plain-text string.
  • Return type : string.

EXAMPLE

Here is the simple example of decode.

Example of decode library:-

Codeigniter Encrypt Class Library

3. Set cipher

This function permit you to set Mcrypt cipher :-

  • Parameters :
  • $cipher (int) : Valid php MCrypt cypher constant.
  • Returns : CI_Encrypt instance.
  • Return type : CI_Encrypt.

EXAMPLE

Here is the simple example of set cipher.

Example of set cipher library:-

Codeigniter Encrypt Class Library

4. Set mode

This function permit you to set Mcrypt mode :-

  • Parameters :
  • $mode (int) : Valid PHP MCrypt mode constant.
  • Returns : CI_Encrypt instance (method chaining).
  • Return type : CI_Encrypt.

EXAMPLE

Here is the simple example of set mode.

Example of set mode library:-

Codeigniter Encrypt Class Library

Advertisements