As other answer suggest MD5 is not encryption methodology for that you need to go for the some encryption Algorithm.
I will say you should go with AES Encryption which is the best in industry and you will get supported classes in each language i.e. OBJC/PHP/JAVA/.NET/NODE.JS etc.
Since you are working in the CodeIgnitor i have one library which you may use directly and i hope it will solve your problems.
Here is the Library code, Just to update you its using the MCRYPT extension of the php which is generally enabled in most of the servers.
Library Class
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
Class Api_encrypt
{
protected $CI;
private $_encryptKey;
private $_MD5Key;
private $_MD5IV;
private $_apiParams;
public function __construct()
{
$this->CI = & get_instance();
$this->_encryptKey = $this->CI->config->item("WS_ENC_KEY");
$this->_MD5Key = substr(md5($this->_encryptKey), 0, 16);
$this->_MD5IV = str_repeat("\0", mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC));
}
public function encrypt($sValue = '')
{
$block = 16;
$pad = $block - (strlen($sValue) % $block);
$sValue .= str_repeat(chr($pad), $pad);
$str_output = base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $this->_MD5Key, $sValue, MCRYPT_MODE_CBC, $this->_MD5IV));
$str_output = str_replace(array('+', '/', '='), array('-', '_', '.'), $str_output);
return $str_output;
}
public function decrypt($sValue = '')
{
//$sValue = str_replace('~','+',$sValue);
$sValue = str_replace(array('-', '_', '.'), array('+', '/', '='), $sValue);
$sValue = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $this->_MD5Key, base64_decode($sValue), MCRYPT_MODE_CBC, $this->_MD5IV);
$block = 16;
$pad = ord($sValue[($len = strlen($sValue)) - 1]);
$len = strlen($sValue);
$pad = ord($sValue[$len - 1]);
$str_output = substr($sValue, 0, strlen($sValue) - $pad);
return $str_output;
}
public function encryptData($sValue = '')
{
$block = 16;
$pad = $block - (strlen($sValue) % $block);
$sValue .= str_repeat(chr($pad), $pad);
$str_output = base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $this->_MD5Key, $sValue, MCRYPT_MODE_CBC, $this->_MD5IV));
return $str_output;
}
public function decryptData($sValue = '')
{
$str_output = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $this->_MD5Key, base64_decode($sValue), MCRYPT_MODE_CBC, $this->_MD5IV);
$block = 16;
$pad = ord($str_output[($len = strlen($str_output)) - 1]);
$len = strlen($str_output);
$pad = ord($str_output[$len - 1]);
$str_output = substr($str_output, 0, strlen($str_output) - $pad);
return $str_output;
}
public function decrypt_params($request_arr = array())
{
if (!is_array($request_arr) || count($request_arr) == 0) {
return $request_arr;
}
foreach ($request_arr as $key => $val) {
$param_val = str_replace(' ', '+', $val);
$request_arr[$key] = $this->decryptData($param_val);
}
return $request_arr;
}
}
Here is the code about how to use this library.
//In Controller
$request_params = $this->input->get_post(NULL, TRUE);
$this->load->library('api_encrypt');
$decrypt_params = $this->api_encrypt->decrypt_params($request_params);
//do operations
//prepare response array
$encrypt_str = $this->api_encrypt->encrypt($response);
Since you stated you are developing the APIs in PHP - CI i will suggest you to checkout the Tool > Configure.IT , They provide a visual interface by which we can create the API and they will also provide generated source code for the API which we can use to deploy on our own servers. I have used that for some projects and it really helped me.