#1 (permalink)  
Old 06-16-2009, 09:21 PM
Administrator
 
Join Date: Apr 2008
Posts: 151
Default Mcrypt Encryption module for use with NixBill Automation

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_256MCRYPT_MODE_ECB );
        
$iv mcrypt_create_iv $iv_sizeMCRYPT_RAND );
        
$crypttext mcrypt_encrypt MCRYPT_RIJNDAEL_256$key$dataMCRYPT_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_256MCRYPT_MODE_ECB );
        
$iv mcrypt_create_iv $iv_sizeMCRYPT_RAND );
        
$decrypttext mcrypt_decrypt MCRYPT_RIJNDAEL_256$key$crypttextMCRYPT_MODE_ECB$iv );
        return 
trim $decrypttext );
    }
}
?>
Attached Files
File Type: zip mcrypt.zip (1.0 KB, 1 views)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 04:15 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.2.0