<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Rayhan's blog (raynux.com) &#187; PHP Classes</title>
	<atom:link href="http://raynux.com/blog/tag/php-classes/feed/" rel="self" type="application/rss+xml" />
	<link>http://raynux.com/blog</link>
	<description>Rayhan's Personal Web Blog Site</description>
	<lastBuildDate>Mon, 11 Apr 2011 06:33:57 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>RayCrypt &#8211; PHP Class for Quick Two Way Encryption and Decryption</title>
		<link>http://raynux.com/blog/2010/11/06/raycrypt-php-class-for-quick-two-way-encryption-and-decryption/</link>
		<comments>http://raynux.com/blog/2010/11/06/raycrypt-php-class-for-quick-two-way-encryption-and-decryption/#comments</comments>
		<pubDate>Sat, 06 Nov 2010 13:26:25 +0000</pubDate>
		<dc:creator>rayhan</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[PHP Classes]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[Reference]]></category>
		<category><![CDATA[web security]]></category>
		<category><![CDATA[Credit Card]]></category>
		<category><![CDATA[Decrypt]]></category>
		<category><![CDATA[Decryption]]></category>
		<category><![CDATA[Encrypt]]></category>
		<category><![CDATA[Encryption]]></category>
		<category><![CDATA[Mcrypt]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://raynux.com/blog/?p=205</guid>
		<description><![CDATA[RayCrypt, A simple and easy PHP class for two way encryption and decryption with multiple configurations and plug and play features. Sometimes two way encryption is very much important when it comes in storing credential information. Credit Card, Bank account information, digital signature etc are very important information of user and strongly discouraged to store [...]]]></description>
			<content:encoded><![CDATA[<p><strong>RayCrypt</strong>, A simple and easy PHP class for two way encryption and decryption with multiple configurations and plug and play features.</p>
<p>Sometimes two way encryption is very much important when it comes in storing credential information. Credit Card, Bank account information, digital signature etc are very important information of user and strongly discouraged to store in plain text. These data should always be stored in encrypted format. <a href="http://www.pcicomplianceguide.org/">PCI</a> has a very strict guideline and policy for storing Credit Card Information in database or file.</p>
<p>This class is very handy to solve this type of situation.</p>
<p><strong>Features:</strong></p>
<p>- Simple &amp; Easy to use from anywhere in your application with a single line of code.<br />
- Easily configurable &amp; can work without any configuration.<br />
- Support multiple salt configurations<br />
- Requires PHP Mcrypt library installed<br />
- Static method for encryption and decryption<br />
- Light Weight</p>
<p><strong>Method:</strong></p>
<p>- RayCrypt::encrypt();<br />
- RayCrypt::decrypt();<br />
- RayCrypt::config();<br />
- RayCrypt::padString();</p>
<p><strong>Class:</strong></p>
<p>File: <strong>raycrypt.php</strong></p>
<pre><code>&lt;?php
/**
 * Two way Encryption and Decryption Class.
 *
 * Suitable for storing credential information like credit card, bank account information into the database
 *
 * PHP version 5+
 * - require Mcrypt library installed
 *
 * @package     raynux
 * @subpackage  raynux.labs.crypt
 * @version     1.0
 * @author	Md. Rayhan Chowdhury
 * @license     MIT License http://www.opensource.org/licenses/mit-license.php
 */

/**
 * Encrypt &amp; Decrypt Using PHP MCrypt Library
 *
 * @package     raynux
 * @subpackage  raynux.labs.crypt
 * @author      Md. Rayhan Chowdhury
 */
class RayCrypt{

    /**
     * RayCrypt Instances
     *
     * @var RayCrypt
     */
    protected static $_instances = array();

    /**
     * Secret Salt generated from the key
     *
     * @var string
     */
    protected $_secretKey;

    /**
     * Default Configuration Array
     *
     * @var array
     */
    protected $_defaults = array(
                                    'returnPlainText' =&gt; true,
                                    'salt' =&gt; '7$e4!158f6$%#be533.!@a066!#35428^#%&amp;$*&amp;faa91:!982*#!e07'
                                );

    /**
     * Hold Run-time configuration
     *
     * @var array
     */
    protected $_configs = array();

    /**
     * Class Constructor
     *
     * @param array $options
     */
    private function __construct($options = null) {
        $this-&gt;_setConfig($options);
    }

    /**
     * Get Instance of RayCrypt
     *
     * @param string $configName
     * @param array $options
     * @return RayCrypt
     */
    private static function &amp;_getInstance($configName = null, $options = null) {

        if (empty($configName)) {
            $configName = 'default';
        }

        if (empty(self::$_instances[$configName])) {
            self::$_instances[$configName] = new self($options);
        }

        return self::$_instances[$configName];
    }

    /**
     * Configure the class instance
     *
     * @param array $options  array('salt' =&gt; '', 'returnPlainText' =&gt; true)
     * @return RayCrypt
     */
    protected function &amp;_setConfig($options = null) {

        if (empty($options) || !is_array($options)) {
            $options = array();
        }

        $this-&gt;_configs = array_merge($this-&gt;_defaults, $options);

        if (!empty($this-&gt;_configs['salt'])) {
            $this-&gt;_setSecretKey($this-&gt;_configs['salt']);
        }

        return $this;
    }

    /**
     * Set secret salt for encryption algorithm
     * @param string $key
     * @return RayCrypt
     * @access protected
     */
    protected function &amp;_setSecretKey($key) {
        $this-&gt;_secretKey = md5(substr(sha1($key), 0, 32));
        return $this;
    }

    /**
     *
     * @param  $configName
     * @param  $options
     */
    public static function config($configName, $options = null) {
        $_this = self::_getInstance($configName, $options);
    }

    /**
     * Encrypt using Mcrypt PHP Library
     *
     * @param string $value
     * @param string $configName
     * @return string
     * @access public
     * @static
     */
    public static function encrypt($value, $configName = null) {

        $_this = self::_getInstance($configName);
        $key = $_this-&gt;_secretKey;

        $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
        $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
        $encryped = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $value, MCRYPT_MODE_ECB, $iv);
        if (!empty($_this-&gt;_configs['returnPlainText'])) {
            $encryped = base64_encode($encryped);
        }

        return $encryped;
    }

    /**
     * Decrypt Using Mcrypt
     *
     * @param string $value
     * @param string $configName
     * @return string
     * @access public
     * @static
     */
    public static function decrypt($value, $configName = null) {
        $_this = self::_getInstance($configName);
        $key = $_this-&gt;_secretKey;

        if (!empty($_this-&gt;_configs['returnPlainText'])) {
            $value = base64_decode($value);
        }

        $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
        $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
        return rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key, $value, MCRYPT_MODE_ECB, $iv), "\0\4");
    }

    /**
     * Masks Important Information Padding String
     *
     * helpful in displaying a part of credit card information like
     * 01234567890 will result xxxxxxx7890
     *
     * @param string $string
     * @param integer $length specify negative length to mask from backward
     * @param mask character $maskCharacter
     * @return string
     * @access public
     * @static
     */
    public static function padString($string, $length, $maskCharacter = 'X') {
        $maskString = substr($string, 0, $length);
        $maskString = preg_replace('(.)', $maskCharacter, $maskString);
        $string = $maskString . substr($string, $length);
        return $string;
    }

}

?&gt;</code></pre>
<p>Usage Example: some quick examples are given below to introduce you with the class and it&#8217;s methods.</p>
<pre><code>&lt;?php
/**
 * RayCrypt Example File
 */

/**
 * Load RayCrypt Library
 */
include_once 'raycrypt.php';

/**
 * Basic debug function
 *
 * @param mixed $value
 */
function dump ($value) {
    printf('&lt;pre&gt;%s&lt;/pre&gt;', var_export($value, true));
};

/**
 * Use RayCrypt without any configuration, it uses default configuration
 */
$data = 'My important data';
$encrypted = RayCrypt::encrypt($data);
$decrypted = RayCrypt::decrypt($encrypted);
dump(array('data' =&gt; $data, 'encrypted' =&gt; $encrypted, 'decrypted' =&gt; $decrypted));

/**
 * Output
 array (
  'data' =&gt; 'My important data',
  'encrypted' =&gt; 'JBtn3msE0QIAei/v9oHP5nW2xasbdSeVhAb4nPXqiUA=',
  'decrypted' =&gt; 'My important data',
)
 */

/**
 * Use RayCrypt with a separate configuration salt for creditCard information
 */
RayCrypt::config('creditCard', array('salt' =&gt; 'jdfjsddfsdf!$#fjsdkjfsdfi7*@(@sdhf'));
$data = '01234567890';
$encrypted = RayCrypt::encrypt($data, 'creditCard');
$decrypted = RayCrypt::decrypt($encrypted, 'creditCard');
dump(array('data' =&gt; $data, 'encrypted' =&gt; $encrypted, 'decrypted' =&gt; $decrypted));

/**
 * Output
array (
  'data' =&gt; '01234567890',
  'encrypted' =&gt; 'E9FO62vScqmObOlIXso70Hx8JpEqzVOiac8yuk3/4yM=',
  'decrypted' =&gt; '01234567890',
)
 */

/**
 * Use RayCrypt with a another configuration for bank information
 */
RayCrypt::config('bank', array('salt' =&gt; 'Nothing wrong'));
$data = '884585847';
$encrypted = RayCrypt::encrypt($data, 'bank');
$decrypted = RayCrypt::decrypt($encrypted, 'bank');
dump(array('data' =&gt; $data, 'encrypted' =&gt; $encrypted, 'decrypted' =&gt; $decrypted));

/**
 * Output
array (
  'data' =&gt; '884585847',
  'encrypted' =&gt; 'BnDAjNJq/ZrwEKT9yLVFEVZO0b4/uu2AWRGVhX3mVRw=',
  'decrypted' =&gt; '884585847',
)
 */

dump(RayCrypt::padString('0123456789', -4)); // output 'XXXXXX6789'

?&gt;</code></pre>
<p>Please let me know if you find this class helpful for you..</p>
]]></content:encoded>
			<wfw:commentRss>http://raynux.com/blog/2010/11/06/raycrypt-php-class-for-quick-two-way-encryption-and-decryption/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Microsoft&#8217;s Initiatives for PHP Developers</title>
		<link>http://raynux.com/blog/2009/10/16/microsofts-initiatives-for-php-developers/</link>
		<comments>http://raynux.com/blog/2009/10/16/microsofts-initiatives-for-php-developers/#comments</comments>
		<pubDate>Fri, 16 Oct 2009 06:07:31 +0000</pubDate>
		<dc:creator>rayhan</dc:creator>
				<category><![CDATA[Developer]]></category>
		<category><![CDATA[Interoperability]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[PHP Classes]]></category>
		<category><![CDATA[WebsiteSpark]]></category>
		<category><![CDATA[Windows Azure]]></category>
		<category><![CDATA[PHP Developer]]></category>

		<guid isPermaLink="false">http://raynux.com/blog/?p=161</guid>
		<description><![CDATA[For years Software Engineers have been trying to get the best out of Opensource, PHP and Microsoft Products. Because of Microsoft business policy they were not successful enough. Finally, Microsoft understood the reality and started to bend towards PHP. Now they wants to make their Platform more compatible to work with PHP. Microsoft has taken [...]]]></description>
			<content:encoded><![CDATA[<p>For years Software Engineers have been trying to get the best out of Opensource, PHP and Microsoft Products. Because of Microsoft business policy they were not successful enough. Finally, Microsoft understood the reality and started to bend towards PHP. Now they wants to make their Platform more compatible to work with PHP. Microsoft has taken several initiatives to open their door for PHP Developers. Some of them are explained bellow:</p>
<p><strong>WebsiteSpark:</strong></p>
<p>It aims to promote the careers of PHP and other Web professionals in general that are interested in specializing in the Microsoft technologies. Under this project they will provide software, support and visibility to the Web Professionals. It&#8217;s a three years long program and you will have to pay a one time program fee of  $100 which is due upon exit or at the end of three years term.</p>
<p>Once enrolled, they are giving away following software products:</p>
<p>- Visual Studio 2008 Professional Edition &#8211; 3 licences<br />
- Expression Studio 3 &#8211; 1 licence<br />
- Expression Web 3 &#8211; 2 licences<br />
- Windows Web Server 2008 R2 &#8211; licences for 4 processors (production and development)<br />
- SQL Server 2008 Web Edition &#8211; licences for 4 processors (production and development)<br />
- DotNetPanel Control Panel</p>
<p>These offer is for small company having employees 10 or less than 10.</p>
<p>You can find more details on project website: <a title="http://www.microsoft.com/web/websitespark/" href="http://www.microsoft.com/web/websitespark/">http://www.microsoft.com/web/websitespark/</a></p>
<p>A Microsoft Manager (Galileu Vieira) explained the offer in details in an interview with PHPClasses.org here: <a title="http://www.phpclasses.org/blog/post/102-Microsoft-promotes-the-careers-of-PHP-professionals.html" href="http://www.phpclasses.org/blog/post/102-Microsoft-promotes-the-careers-of-PHP-professionals.html">http://www.phpclasses.org/blog/post/102-Microsoft-promotes-the-careers-of-PHP-professionals.html</a><br />
. And if you read this blog post then I suggest to read the following comment tread also. <a title="http://www.phpclasses.org/discuss/blog/PHP-Classes-blog/post/102/thread/12/" href="http://www.phpclasses.org/discuss/blog/PHP-Classes-blog/post/102/thread/12/">http://www.phpclasses.org/discuss/blog/PHP-Classes-blog/post/102/thread/12/</a></p>
<p>Here is another post on Microsoft and PHP at PHPClasses.org: <a title="http://www.phpclasses.org/blog/post/85-What-is-Microsoft-up-to-with-PHP.html" href="http://www.phpclasses.org/blog/post/85-What-is-Microsoft-up-to-with-PHP.html">http://www.phpclasses.org/blog/post/85-What-is-Microsoft-up-to-with-PHP.html<br />
</a></p>
<p><strong>Interoperability:</strong></p>
<p>A Center run by Microsoft Interoperability Strategy Group, which is dedicated to technical collaborative work to improve interoperability between Microsoft and non-Microsoft technologies. In this site, you will find a live directory of freely downloadable technical interoperability Bridges &amp; Labs and related content such as demos, technical guidance and articles. The vast majority of the projects are Open Source. Here you will meet with PHP Interoperability projects and technologies.</p>
<p>Mode details at Centers website: <a title="http://www.interoperabilitybridges.com/Default.aspx" href="http://www.interoperabilitybridges.com/Default.aspx">http://www.interoperabilitybridges.com/Default.aspx<br />
</a></p>
<p><strong>Windows Azure:</strong></p>
<p>What is Windows Azure? In their words, it is Microsoft&#8217;s Platform to run interoperable application and services. Windows Azure is a runtime environment in the cloud that delivers on-demand compute, storage, and automated systems management. Windows Azure provides developers with the ability to host, scale, and manage Web applications on the Internet through Microsoft data centers.</p>
<p>More details at Windows Azure website: <a title="http://www.azure.com/" href="http://www.azure.com/">http://www.azure.com/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://raynux.com/blog/2009/10/16/microsofts-initiatives-for-php-developers/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

