B2C Service Encryption Example
<?php
namespace Custom\Libraries;
use RightNow\Connect\v1_4 as RNCPHP,
   RightNow\Connect\Crypto\v1_4 as Crypto;
class Encryption
{
    /**
     * This library can be loaded a few different ways depending on where it's being called:
     *
     * From a widget or model: $this->CI->load->library('Encryption');
     *
     * From a custom controller: $this->load->library('Encryption');
     *
     * Everywhere else, including other libraries: $CI = get_instance();
     *                                             $CI->load->library('Encryption')->encrypt();
     */
    function __construct(){
        $context = RNCPHP\ConnectAPI::getCurrentContext();
        $context->ApplicationContext = "EncryptCpHelper";
    }
    function encrypt($str){
        $cipher = new Crypto\AES();
        $cipher->Mode->ID =1;
        $cipher->IV->Value = "1234567812345678";
        $cipher->KeySize->LookupName = "128_bits";
        $cipher->Text = $str;
        $cipher->KeyDerivative = new Crypto\CryptoKeyDerivative();
        $cipher->KeyDerivative->Mode->ID = 2;
        $cipher->KeyDerivative->Salt = new Crypto\CryptoKeyDerivativeSalt();
        $cipher->KeyDerivative->Salt->Value = "HGTRFSRUIKHGBVFD";
        $cipher->KeyDerivative->Password = "z3&|]5)b qK~N(w";
        $cipher->KeyDerivative->Iteration = 1000;
        $cipher->encrypt();
        $encrypted_text = $cipher->EncryptedText;
        return base64_encode($encrypted_text);
    }
    function decrypt($str){
        $cipher = new Crypto\AES();
        $cipher->Mode->ID =1;
        $cipher->IV->Value = "1234567812345678";
        $cipher->KeySize->LookupName = "128_bits";
        $cipher->EncryptedText = $str;
        $cipher->KeyDerivative = new Crypto\CryptoKeyDerivative();
        $cipher->KeyDerivative->Mode->ID = 2;
        $cipher->KeyDerivative->Salt = new Crypto\CryptoKeyDerivativeSalt();
        $cipher->KeyDerivative->Salt->Value = "HGTRFSRUIKHGBVFD";
        $cipher->KeyDerivative->Password = "z3&|]5)b qK~N(w";
        $cipher->KeyDerivative->Iteration = 1000;
        $cipher->decrypt();
        $decrypted_text = $cipher->Text;
        return $decrypted_text;
    }
}
 
				
