This is a basic encryption module using the php mcrypt extension.
to use this module download the attached file and extract it into your "encryption-modules" folder.
PHP Code:
<?php
class mcrypt {
/**
* Module ID in NixBill system
*
* @var int
*/
private $ModuleId;
/**
* Private decryption key
*
* @var string
*/
private $Key;
public function __construct($moduleid = false) {
/**
* If the module ID is not sent then we dont need to call for the options.
* The only reason to not have the module ID would be when creating new modules
*/
if($moduleid){
$this->ModuleId = $moduleid;
$options = $this->GetModuleOptions ();
$this->Key = $options ['NIXBILL'] [0] ['RESULT'] [0] ['OPTIONS'] [0] ['OPTION_KEY'] [0] ['VALUE'];
}
}
public function ModuleOptions() {
/**
* Each of these options will create an option on the admin page for this module.
*/
$options = array (
array ('formtype' => 'text', 'description' => LANG_NAME, 'name' => 'name', 'value' => 'Mcrypt Encryption Module' ),//
array ('formtype' => 'text', 'description' => 'Secret Key', 'name' => 'key', 'value' => 'secret key' ) //
);
return $options;
}
public function GetModuleOptions() {
$xml = '<nixbill>
<command>GetEncryptionModule</command>
<hash>' . GetApiHash () . '</hash>
<moduleid>' . $this->ModuleId . '</moduleid>
</nixbill>
';
$result = API ( $xml );
return $result;
}
/**
* If a key is required to decrypt using this module the key will be set with this method.
*/
public function SetPrivateKey($key) {
$this->Key = $key;
}
/**
* Retrun "true" if this module requires a key to decrypt the data. if not return "false"
*/
public function KeyRequiredToDecrypt() {
return false;
}
/**
* Main encryption function
* Use this method to create your encryption setup.
*/
public function Encrypt($data) {
$key = $this->Key;
$iv_size = mcrypt_get_iv_size ( MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB );
$iv = mcrypt_create_iv ( $iv_size, MCRYPT_RAND );
$crypttext = mcrypt_encrypt ( MCRYPT_RIJNDAEL_256, $key, $data, MCRYPT_MODE_ECB, $iv );
return trim ( base64_encode ( $crypttext ) );
}
/**
* Main decryption function
* Use this method to create your decryption setup.
*/
public function Decrypt($data) {
$key = $this->Key;
$crypttext = base64_decode ( $data );
$iv_size = mcrypt_get_iv_size ( MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB );
$iv = mcrypt_create_iv ( $iv_size, MCRYPT_RAND );
$decrypttext = mcrypt_decrypt ( MCRYPT_RIJNDAEL_256, $key, $crypttext, MCRYPT_MODE_ECB, $iv );
return trim ( $decrypttext );
}
}
?>