<?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>epicgeeks.net</title>
	<atom:link href="http://epicgeeks.net/feed/" rel="self" type="application/rss+xml" />
	<link>http://epicgeeks.net</link>
	<description>gaming, development, and life.</description>
	<lastBuildDate>Tue, 07 Aug 2012 14:20:36 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.4.1</generator>
		<item>
		<title>DeadFish.Lib PHP Hashing</title>
		<link>http://epicgeeks.net/deadfish-lib-php-hashing/</link>
		<comments>http://epicgeeks.net/deadfish-lib-php-hashing/#comments</comments>
		<pubDate>Mon, 23 Jul 2012 20:12:03 +0000</pubDate>
		<dc:creator>J. Newing</dc:creator>
				<category><![CDATA[Cryptography]]></category>
		<category><![CDATA[Misc.]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://epicgeeks.net/?p=116</guid>
		<description><![CDATA[I recently saw a post on forrst.com about safely (or as safe as possible) storing a hash of a users password. So I figured I would share my DeadFish PHP library that implements adaptive hashes using blowfish and it&#8217;s algorithm’s keying schedule. Library is fairly simple to use while allowing users to customize it, via ...]]></description>
			<content:encoded><![CDATA[<p>I recently saw a post on forrst.com about safely (or as safe as possible) storing a hash of a users password.</p>
<p>So I figured I would share my DeadFish PHP library that implements adaptive hashes using blowfish and it&#8217;s algorithm’s keying schedule. Library is fairly simple to use while allowing users to customize it, via a simple options array.</p>
<p>Example / Demo: <a href="http://epicgeeks.net/deadfish/demo.php">http://epicgeeks.net/deadfish/demo.php</a></p>
<p>Source: <a href="https://bitbucket.org/jnewing/deadfish-lib">https://bitbucket.org/jnewing/deadfish-lib</a></p>
<p><span id="more-116"></span></p><pre class="crayon-plain-tag">&amp;lt;?php

/**
 * DeadFish Library
 * The DeadFish library is used for making a safe (or safer) storable hash of a user password. We attempt to make storing a password hash
 * a little more secure by creating an adaptive hash using blowfish and it's algorithm&rsquo;s keying schedule.
 *
 * @author      Joseph Newing (jnewing [at] gmail [dot] com)
 * @copyright   Joseph Newing 2011 - 2012
 * @link        https://bitbucket.org/jnewing/deadfish-lib
 * @link        http://epicgeeks.net
 * @version     1.4
 *
 * *************************************************************************************************************************
 *
 * DeadFish lib has several options users can set to customize this library.
 *
 * Options:
 *      min_length          - the minamum required length of a user password
 *      strict_password     - require the password to follow &quot;strict&quot; rules (see rules below)
 *                              o min length required
 *                              o require alpha and numeric values
 *                              o require both upper and lower case values
 *      work_factor         - the work factor
 *
 * Within this class there are both static function users can use for fast access as
 * well as none static ones, see examples below.
 *
 * Static Usage Examples:
 *
 * static function example:
 * $hash = DeadFish::computeHash('some password');      // would compute a hash with default work factor
 *
 * static function check and existing hash
 * $bool = DeadFish::verifyHash('some password', 'matching hash');
 *
 * Object Usage Example:
 *
 * example with default options:
 *
 * $df = new DeadFish();
 * $df-&amp;gt;set_password('some_password');
 * $hash = $df-&amp;gt;hash();
 * ...
 * if ($df-&amp;gt;verify('some_password', 'some_hash'))
 *  do stuff...
 *
 * example with diff options:
 *
 * $options = array(
 *      'min_length'        =&amp;gt; 5,       // make the min password length 5
 *      'strict_password'   =&amp;gt; TRUE     // use strict passwords
 * );
 *
 * $df = new DeadFish($options);
 * $hash = $df-&amp;gt;hash('some_password')
 *
 */

class DeadFish
{

// ======================================================================================
//  class consts
// ======================================================================================

    const DEFAULT_WORK_FACTOR   = 9;

// ======================================================================================
//  public variables
// ======================================================================================

    /**
     * minimum lenght the password must be
     */
    public $min_length          = 8;

    /**
     * strict password must be at least ^ min length (see above)
     * alpha numeric and contain at least one uppercase and one lower case character
     */
    public $strict_password     = FALSE;

    /**
     * our work factor
     */
    public $work_factor         = 9;

// ======================================================================================
//  private variables
// ======================================================================================

    /**
     * user password
     */
    private $password            = NULL;

// ======================================================================================
//  public functions
// ======================================================================================

    /**
     * constructor - Sets some default PHash prefs.
     *
     * the constructor can be passed an array of config values however this is not
     * needed unless you wish to do some customization of your own.
     */
    public function __construct($options = FALSE)
    {
        if ($options)
            $this-&amp;gt;init($options);
    }

    // --------------------------------------------------------------------

    /**
     * initialize our prefs.
     *
     * @access  public
     * @param   array
     * @return  void
     */
    public function init($options)
    {
        // setup our default options
        if (is_array($options))
        {
            foreach ($options as $key =&amp;gt; $val)
                $this-&amp;gt;{$key} = $val;
        }
    }

    // --------------------------------------------------------------------

    /**
     * set_password function will set the class password while doing
     * the required checks.
     *
     * @access  public
     * @param   string
     * @return  void
     */
    public function set_password($password)
    {
        // we are forcring the user to set a strong password
        // password rules:
        //  - min length required
        //  - require alpha and numeric values
        //  - require both upper and lower case values
        if ($this-&amp;gt;strict_password)
        {
            if (preg_match('/\A(?=[\x20-\x7E]*?[A-Z])(?=[\x20-\x7E]*?[a-z])(?=[\x20-\x7E]*?[0-9])[\x20-\x7E]{' . $this-&amp;gt;min_length . ',}\z/', $password))
            {
                // set the password
                $this-&amp;gt;password = $password;

                // return
                return;
            }
            else
                throw new Exception('Password did not meat minamum security requirements.');
        }

        // if we are not forcing the user to a strict password then we should at the very least
        // make it a min. length
        if (strlen($password) &amp;gt;= $this-&amp;gt;min_length)
        {
            // set our password
            $this-&amp;gt;password = $password;

            // return
            return;
        }

        throw new Exception('Password did not meat minamum security requirements.');
    }

    // --------------------------------------------------------------------

    /**
     * set the work factor for the class
     *
     * @access  public
     * @param   int
     * @return  void
     */
    public function set_work($work)
    {
        // make sure work fact. is between 4 and 31, if not we error.
        if ($work &amp;lt; 4 || $work &amp;gt; 31)
            throw new Exception('Work factor must be between 4 and 31.');

        // if we are good set it
        $this-&amp;gt;work_factor = $work;
    }
    // --------------------------------------------------------------------

    /**
     * hash function allows users to hash a password using the initialized class this will look to
     * $this-&amp;gt;password (hopefully set by set_password or has been passed to this function)
     *
     * @access  public
     * @param   string (optional)
     * @return  string
     */
    public function hash($password = FALSE)
    {
        // if the user passed our password here lets try and set it
        if ($password)
            $this-&amp;gt;set_password($password);

        // make sure we have a password to hash
        if (empty($this-&amp;gt;password))
            throw new Exception('Missing a password?');

        // lets hash
        return self::computeHash($this-&amp;gt;password, $this-&amp;gt;work_factor);
    }

    // --------------------------------------------------------------------

    /**
     * verify function allows the user to verify a password and hash match, simply returns a bool value
     * user can then do what they like with the result.
     *
     * @access  public
     * @param   string (optional)
     * @param   string (optional)
     * @return  bool
     */
    public function verify($password = FALSE, $hash = FALSE)
    {
        if ($password)
            $this-&amp;gt;password = $password;

        if ($hash)
            $this-&amp;gt;hash = $hash;

        // make sure we have a password and hash to work with
        if (empty($this-&amp;gt;password) || empty($this-&amp;gt;hash))
            throw new Exception('Missing password or hash?');

        // compair and return
        return self::verifyHash($this-&amp;gt;password, $this-&amp;gt;hash);
    }

    // --------------------------------------------------------------------

// ======================================================================================
//  public static functions
// ======================================================================================

    /**
     * compute the hash of the password using the specified work factor value, if no work factor is
     * specified then default (8) will be used
     *
     * @access  public
     * @param   string
     * @param   int
     * @return  string
     */
    public static function computeHash($password, $work = 0)
    {
        // declair our salt
        $salt = NULL;

        // define our work fact.
        $work = ($work &amp;lt; 4 || $work &amp;gt; 31) ? self::DEFAULT_WORK_FACTOR : $work;

        // random pseudo bytes
        if (function_exists('openssl_random_pseudo_bytes'))
            $random_bytes = substr(strtr(base64_encode(openssl_random_pseudo_bytes(16)), '+', '.'), 0, 22);
        else
            $random_bytes = self::gen_random();

        // gen our salt
        $salt = '$2a$' . str_pad($work, 2, '0', STR_PAD_LEFT) . '$' . $random_bytes;

        // return our hash
        return crypt($password, $salt);
    }

    // --------------------------------------------------------------------

    /**
     * verify the password and hash passed to this function
     *
     * @access  public
     * @param   string
     * @param   string
     * @return  bool
     */
    public static function verifyHash($password, $hash)
    {
        // if this is not a blowfish hash we can just error as we don't
        // understand how to deal with it
        if (substr($hash, 0, 4) != '$2a$')
            throw new Exception('Unknown or invalid hash format.');

        // crypt compair and return
        return crypt($password, $hash) === $hash;
    }

    // --------------------------------------------------------------------

// ======================================================================================
//  private functions
// ======================================================================================

    /**
     * gen_random function is to be used in place of the openssl_random_pseudo_bytes function,
     * we would rather use that function however not all system will have that available so this is
     * used as a fallback
     *
     * @access  public
     * @param   int (optional)
     * @return  string
     */
    private static function gen_random($length = 22)
    {
        $ascii_array = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789./';
        $random_string = '';

        for ($x = 0; $x &amp;lt; $length; $x++)
            $random_string .= $ascii_array[ rand(0, 63) ];

        return $random_string;
    }

    // --------------------------------------------------------------------

}

?&amp;gt;</pre><p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://epicgeeks.net/deadfish-lib-php-hashing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>IDA Patcher for Windows</title>
		<link>http://epicgeeks.net/ida-patcher-for-windows/</link>
		<comments>http://epicgeeks.net/ida-patcher-for-windows/#comments</comments>
		<pubDate>Wed, 21 Dec 2011 01:33:20 +0000</pubDate>
		<dc:creator>J. Newing</dc:creator>
				<category><![CDATA[Other]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://epicgeeks.net/?p=23</guid>
		<description><![CDATA[Not too long ago I found myself needing to patch a .dll with a .dif file produced from IDA, after a very quick and admittedly quite lazy google turned up nothing I decided I needed to just write a quick one. I figured I would share with you the result. It&#8217;s quite simple, select the ...]]></description>
			<content:encoded><![CDATA[<p>Not too long ago I found myself needing to patch a .dll with a .dif file produced from IDA, after a very quick and admittedly quite lazy google turned up nothing I decided I needed to just write a quick one. I figured I would share with you the result.</p>
<p>It&#8217;s quite simple, select the target file you wish to patch and select a .dif file with the patches you wish to make. Note: the .dif files produced by IDA need to either have their first 4 lines removed or simply add a ; to the lines with text (turning them into what my patcher sees as a comment and ignores) otherwise it expects a format of:</p>
<p><strong>Example Dif File</strong></p><pre class="crayon-plain-tag">;This difference file has been created by IDA Pro
;
;some file.dll
;
; this is just a sample comment that can be placed inside a .dif file
00005031: 03 17
00005035: 03 17
00005872: 28 00
00005873: 58 00
00005874: 01 00
00005876: 06 00
00005C3A: 18 17
00010F56: 06 16</pre><p></p>
<p>As you can see above this .dif file would make 8 bytes changes within the specified target file.</p>
<p><a href="http://epicgeeks.net/2011/12/ida-patcher-for-windows/ida_patcher/" rel="attachment wp-att-24"><img class="alignnone size-medium wp-image-24" title="ida_patcher" src="http://epicgeeks.net/wp-content/uploads/2011/12/ida_patcher-300x233.png" alt="" width="300" height="233" /></a></p>
<a class="downloadlink" href="http://epicgeeks.net/wp-content/plugins/download-monitor/download.php?id=3" title=" downloaded 898 times" >IDAPatch (898)</a>
]]></content:encoded>
			<wfw:commentRss>http://epicgeeks.net/ida-patcher-for-windows/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>WordPress Crayon Plugin</title>
		<link>http://epicgeeks.net/wordpress-crayon-plugin/</link>
		<comments>http://epicgeeks.net/wordpress-crayon-plugin/#comments</comments>
		<pubDate>Tue, 25 Oct 2011 18:33:08 +0000</pubDate>
		<dc:creator>J. Newing</dc:creator>
				<category><![CDATA[Other]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://epicgeeks.net/?p=21</guid>
		<description><![CDATA[So as I&#8217;ve been designing this blog I decided I needed a good syntax highlighter as hopefully I&#8217;ll be posting lots of yummy source code for all kinds of interesting things. After a little while of searching I discovered found Crayon Syntax Highlighter by Aram Kocharyan, in short. WOW. This plugin is wonderful, uses jQuery ...]]></description>
			<content:encoded><![CDATA[<p>So as I&#8217;ve been designing this blog I decided I needed a good syntax highlighter as hopefully I&#8217;ll be posting lots of yummy source code for all kinds of interesting things. After a little while of searching I discovered found <a href="http://ak.net84.net/projects/crayon-syntax-highlighter/">Crayon Syntax Highlighter</a> by Aram Kocharyan, in short. WOW. This plugin is wonderful, uses jQuery and boasts a robust, but elegant syntax highlighting schema.</p>
<p>Hands down this plugin has been wonderful to use in every way, the only think I found it lacked (that I personally wanted) was the ability to pop code out of my blog into a another window, as you can see this blog is very thin and makes for lack luster code reading. After a quick contact with the plugin&#8217;s author low and behold the same day he build the feature into the plugin. How&#8217;s that for service! </p>
<p>Finally I built my own theme, for here at epicgeeks.net however I&#8217;ve made this theme available for download here: <a class="downloadlink" href="http://epicgeeks.net/wp-content/plugins/download-monitor/download.php?id=2" title="Version1.0 downloaded 425 times" >Epicgeeks Crayon Theme (425)</a></p>
]]></content:encoded>
			<wfw:commentRss>http://epicgeeks.net/wordpress-crayon-plugin/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using PKs C# to PHP</title>
		<link>http://epicgeeks.net/using-pks-c-to-php/</link>
		<comments>http://epicgeeks.net/using-pks-c-to-php/#comments</comments>
		<pubDate>Mon, 24 Oct 2011 18:18:43 +0000</pubDate>
		<dc:creator>J. Newing</dc:creator>
				<category><![CDATA[Cryptography]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://epicgeeks.net/?p=7</guid>
		<description><![CDATA[So lately I&#8217;ve been seeing more and more C# application talking to the web, web interaction and applications is something that can be beneficial to both the end user and the developer making a plethora of things simpler and streamlined. However while talking two and from you application one needs to make sure the information is ...]]></description>
			<content:encoded><![CDATA[<p>So lately I&#8217;ve been seeing more and more C# application talking to the web, web interaction and applications is something that can be beneficial to both the end user and the developer making a plethora of things simpler and streamlined. However while talking two and from you application one needs to make sure the information is secure at all times.</p>
<p>There are several methods to doing this, and one way is using public, private key-pair cryptography. In the example below I&#8217;ve shown a PHP script that is able to talk to a C# application using an openssl public, private key-pair.</p>
<p>In this post I&#8217;ve included <span id="more-7"></span>the source to everything in a .rar file listed for download at the bottom.</p>
<p><strong>Openssl Class</strong></p><pre class="crayon-plain-tag">&lt;?php


/**
 ******************************************************************************************
 * OpenSSL                                                                    * synmuffin *
 ******************************************************************************************
 * 
 * OpenSSL class that was designed to work with C/C++/C# applications. This class allows
 * users who want to build a secure API to Rx/Tx data from the web (website or server)
 * through to their end users application.
 * 
 *
 * author: synmuffin
 * email: synmuffin@savelab.net
 * version: 1.0
 * date:
 *
 */
class OpenSSL {
	
	/*
	|================================================================================
	| PUBLIC VARS
	|================================================================================
	*/


	/*
	|================================================================================
	| PRIVATE VARS
	|================================================================================
	*/
	
	
	/**
	 * $publicKey
	 * Public key instance used throughout the class. This must be initialized via the
	 * LoadPublicKey() function.
	 */
	private $publicKey 		= NULL;
	
	
	/**
	 * $privateKey
	 * Private key instance used throughout the class. This must be initialized via the
	 * LoadPrivateKey() function.
	 */
	private $privateKey 	= NULL;


	/**
	 * $padding
	 * Padding, currently not in use as it seems to not work.
	 */
	private $padding 		= NULL;		// OPENSSL_PKCS1_PADDING, OPENSSL_SSLV23_PADDING, OPENSSL_PKCS1_OAEP_PADDING, OPENSSL_NO_PADDING.

    
    /**
     * Class constructor, currently no paramaters are needed.
     */
    public function __construct($params = FALSE)
    {
        if (!$params)
            return;
        
        if (array_key_exists('public_key', $params))
        {
            if (file_exists($params['public_key']))
                $this-&gt;LoadPublicKey($params['public_key']);
            else
                trigger_error(&quot;Unable to find Public key file {$params['public_key']}.&quot;, E_USER_ERROR);
        }

        if (array_key_exists('private_key', $params))
        {
            if (file_exists($params['private_key']))
                $this-&gt;LoadPrivateKey($params['private_key']);
            else
                trigger_error(&quot;Unable to find Private key file {$params['private_key']}.&quot;, E_USER_ERROR);
        }
    }
    // ---------------------------------------------------------------------


    /*
	|================================================================================
	| PUBLIC FUNCTIONS
	|================================================================================
	*/

    
    /**
     * public LoadPrivateKey(string $privkey_path [, string $privkey_pass])
     *
     * Function will load a private key via the passed string file location of $privkey_path. This fucntion also
     * takes and optional second paramter that will allow for private keys locked with a DES passphrase to be used.
     *
     * @param string $privkey_path	- Path to the private key file.
     * @param string $privkey_pass	- Private key passphrase.
     *
     * @return none
     */
    public function LoadPrivateKey($privkey_path, $privkey_pass = FALSE)
    {
    	if (!$privkey_pass || $privkey_pass == NULL)
    	{
    		if (!($this-&gt;privateKey = openssl_get_privatekey('file://' . $privkey_path)))
    			trigger_error(&quot;Unable to load private key from file {$privkey_path}.&quot;, E_USER_ERROR);
    	}
    	else
    	{
    		if (!($this-&gt;privateKey = openssl_get_privatekey('file://' . $privkey_path, $privkey_pass)))
    			trigger_error(&quot;Unable to load private key from file {$privkey_path}.&quot;, E_USER_ERROR);
    	}
    }
    // ---------------------------------------------------------------------


    /**
     * public LoadPublicKey(string $pubkey_path)
     *
     * Function will load a public key via the passed string file location of $pubkey_path.
     *
     * @param string $pubkey_path 	- Path to public key file.
     *
     * @return none
     */
    public function LoadPublicKey($pubkey_path)
    {
    	if (!($this-&gt;publicKey = openssl_get_publickey('file://' . $pubkey_path)))
    		trigger_error(&quot;Unable to load public key from file {$pubkey_path}.&quot;, E_USER_ERROR);
    }
    // ---------------------------------------------------------------------

    
    /**
     * public PrivateKeyEncrypt(string $raw_data [, bool $base64 = TRUE])
     *
     * Function will try and encrypte the passed string $raw_data using the loaded (hopefully) $this-&gt;privateKey
     * resource. This function also takes an optional second paramter allowing the user to spepcified if they wish
     * to have the encrypted data returned base64 encoded, be default this is set to true.
     *
     * @param string $raw_data	- Raw data to be encrypted.
     * @param bool $base64 		- Bool value to return data base64 encoded.
     *
     * @return string $encrypted_data
     */
    public function PrivateKeyEncrypt($raw_data, $base64 = TRUE)
    {
    	if ($this-&gt;privateKey == NULL)
    		trigger_error(&quot;Private key has not been sepcified.&quot;, E_USER_ERROR);
		
    	if (!openssl_private_encrypt($raw_data, $encrypted_data, $this-&gt;privateKey))
    		trigger_error(&quot;Unable to encrypt data.&quot;, E_USER_ERROR);

    	return ($base64) ? base64_encode($encrypted_data) : $encrypted_data;
    }
    // ---------------------------------------------------------------------

    
    /**
     * public PrivateKeyDecrypt(string $raw_data [, bool $base64 = TRUE])
     *
     * Function will try and decrypt the passed $raw_data using the loaded (hopefully) $this-&gt;privateKey resource. This
     * function, much like it's counter-part, takes an optional second paramter specifiing whether or not the $raw_data
     * is base64 encoded. By default is assumes it is.
     *
     * @param string $raw_data 	- Raw data to be decrypted.
     * @param bool $base64 		- Bool value to assume $raw_data is base64 encoded.
     *
     * @return string $decrypted_data
     */
    public function PrivateKeyDecrypt($raw_data, $base64 = TRUE)
    {
		if ($this-&gt;privateKey == NULL)
			trigger_error(&quot;Private key has not been specified.&quot;, E_USER_ERROR);

    	
    	if (!openssl_private_decrypt(($base64) ? base64_decode($raw_data) : $raw_data, $decrypted_data, $this-&gt;privateKey, $this-&gt;padding))
    			trigger_error(&quot;Unable to decrypt data.&quot;, E_USER_ERROR);

    	return $decrypted_data;
    }
    // ---------------------------------------------------------------------

    
    /**
     * public PublicKeyEncrypt(string $raw_data [, bool $base64 = TRUE])
     *
     * Function will try and encrypte the passed string $raw_data using the loaded (hopefully) $this-&gt;publicKey
     * resource. This function also takes an optional second paramter allowing the user to spepcified if they wish
     * to have the encrypted data returned base64 encoded, be default this is set to true.
     *
     * @param string $raw_data	- Raw data to be encrypted.
     * @param bool $base64 		- Bool value to return data base64 encoded.
     *
     * @return string $encrypted_data
     */
    public function PublicKeyEncrypt($raw_data, $base64 = TRUE)
    {
    	if ($this-&gt;publicKey == NULL)
    		trigger_error(&quot;Public key has not been specified.&quot;, E_USER_ERROR);

    	if (!openssl_public_encrypt($raw_data, $encrypted_data, $this-&gt;publicKey))
    		trigger_error(&quot;Unable to encrypt data.&quot;, E_USER_ERROR);

    	return ($base64) ? base64_encode($encrypted_data) : $encrypted_data;
    }
    // ---------------------------------------------------------------------

    
    /**
     * public PublicKeyDecrypt(string $raw_data [, bool $base64 = TRUE])
     *
     * Function will try and decrypt the passed $raw_data using the loaded (hopefully) $this-&gt;privateKey resource. This
     * function, much like it's counter-part, takes an optional second paramter specifiing whether or not the $raw_data
     * is base64 encoded. By default is assumes it is.
     *
     * @param string $raw_data 	- Raw data to be decrypted.
     * @param bool $base64 		- Bool value to assume $raw_data is base64 encoded.
     *
     * @return string $decrypted_data
     */
    public function PublicKeyDecrypt($raw_data, $base64 = TRUE)
    {
    	if ($this-&gt;publicKey == NULL)
    		trigger_error(&quot;Public key has not been specified.&quot;, E_USER_ERROR);
    	
    	if (!openssl_public_decrypt(($base64) ? base64_decode($raw_data) : $raw_data, $decrypted_data, $this-&gt;publicKey))
    		trigger_error(&quot;Unable to decrypt data.&quot;, E_USER_ERROR);
    	
    	return $decrypted_data;
    }
    // ---------------------------------------------------------------------


    /*
	|================================================================================
	| PRIVATE FUNCTIONS
	|================================================================================
	*/
	

}
?&gt;</pre><p></p>
<p><strong>Web usage example</strong></p><pre class="crayon-plain-tag">&lt;?php
	// include the lib
	require_once('../lib/OpenSSL.php');

	// now to keep this nice and secure this should always be done and called
	// over a a HTTPS layer for added security. However in this example I've provided
	// a way to turn this check off just in case you want to run soem quick http tests.
	//
	// Simply comment out the next two lines if you wish to run http NOT https.
	
	if ($_SERVER['HTTPS'] != 'on')
		exit(&quot;You should use HTTPS not HTTP.&quot;);

	// in this example I'm going to use the $raw_data variable and just stick some text data in it,
	// however in a RWS this would be sensitive data that I've returned via a call or check from
	// a database or something along those lines.
	//
	// More to the point I want to pass something back to my application here, as encrypted data.
	$raw_data = &quot;This is my data that I want to keep a secret!&quot;;

	// next we init our class
	$ssl = new OpenSSL();

	// load our private key
	$ssl-&gt;LoadPrivateKey('/home/your/path/to/privatekey.key');

	// now we can encrypt our data (provided the key was valid)
	// note: with default optiosn like this it will return the data base64 encoded
	$encrypted_data = $ssl-&gt;PrivateKeyEncrypt($raw_data);

	// now we are just going to print this data (assuming this was our C# app that made this call)
	// we print the data right to output buffer, so we can use things like HTTP_GET requests.
	print $encrypted_data;
?&gt;</pre><p></p>
<p>Using the above example in conjunction with the C# application you can demo how this would work. Download the attached file to get a copy of all .php files as well as a full C# application.</p>
<a class="downloadlink" href="http://epicgeeks.net/wp-content/plugins/download-monitor/download.php?id=1" title=" downloaded 238 times" >PHP to C# Example (238)</a>
]]></content:encoded>
			<wfw:commentRss>http://epicgeeks.net/using-pks-c-to-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>HashIt C++ (Source Code)</title>
		<link>http://epicgeeks.net/hashit-c-cross-platform-source-code/</link>
		<comments>http://epicgeeks.net/hashit-c-cross-platform-source-code/#comments</comments>
		<pubDate>Fri, 17 Jun 2011 02:32:17 +0000</pubDate>
		<dc:creator>J. Newing</dc:creator>
				<category><![CDATA[Gaming]]></category>
		<category><![CDATA[Misc.]]></category>
		<category><![CDATA[Other]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://zeropair.com/?p=109</guid>
		<description><![CDATA[So here is a little app I&#8217;ve been calling HashIt it&#8217;s a simple rehash / resigner for Windows, Linux and Mac and I&#8217;ve included the source as well. This all kind of came into play as decided I wanted to learn more about STFS and what better way to make a quick and clean rehash ...]]></description>
			<content:encoded><![CDATA[<p>So here is a little app I&#8217;ve been calling HashIt it&#8217;s a simple rehash / resigner for Windows, Linux and Mac and I&#8217;ve included the source as well.</p>
<p>This all kind of came into play as decided I wanted to learn more about STFS and what better way to make a quick and clean rehash /resigner its written in C++ and should work on all platforms.</p>
<p>This does not come with any official support but I&#8217;d be happy to try and answer any question you may have.</p>
<a class="downloadlink" href="http://epicgeeks.net/wp-content/plugins/download-monitor/download.php?id=6" title=" downloaded 2759 times" >Hashit (2759)</a>
<p>Also here is now a binary for Intel Mac</p>
<a class="downloadlink" href="http://epicgeeks.net/wp-content/plugins/download-monitor/download.php?id=7" title="VersionMac 64bit downloaded 447 times" >Hashit Mac (447)</a>
]]></content:encoded>
			<wfw:commentRss>http://epicgeeks.net/hashit-c-cross-platform-source-code/feed/</wfw:commentRss>
		<slash:comments>24</slash:comments>
		</item>
		<item>
		<title>Updates&#8230;</title>
		<link>http://epicgeeks.net/updates/</link>
		<comments>http://epicgeeks.net/updates/#comments</comments>
		<pubDate>Mon, 13 Jun 2011 17:54:08 +0000</pubDate>
		<dc:creator>J. Newing</dc:creator>
				<category><![CDATA[FalloutQt]]></category>
		<category><![CDATA[Mac]]></category>
		<category><![CDATA[Misc.]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://zeropair.com/?p=103</guid>
		<description><![CDATA[So first up I&#8217;m taking a bit of time to play with the site layout of zeropair.com. It&#8217;s something I&#8217;ve been meaning to do for a while now and finally got around to it. Updates on the Fallout Qt front, well it&#8217;s ready to keep it short, however I&#8217;m not releasing it yet as there ...]]></description>
			<content:encoded><![CDATA[<p>So first up I&#8217;m taking a bit of time to play with the site layout of zeropair.com. It&#8217;s something I&#8217;ve been meaning to do for a while now and finally got around to it.</p>
<p>Updates on the Fallout Qt front, well it&#8217;s ready to keep it short, however I&#8217;m not releasing it yet as there are a few things to add, tweak and play with. This is in progress and with that I realize that there are currently no nice rehash/resigners for Linux and Mac. I&#8217;m working on a solution to this. I&#8217;ve not yet named my project but I&#8217;ve created a rehash/resigner for CON files currently it&#8217;s running on Windows, and Mac I&#8217;ve not looked at Linux yet but that will be coming.</p>
<p>I would like the release of this CON file rehash/resigner to coincide with FalloutQt for obvious reasons. As both projects will compliment each other nicely.</p>
]]></content:encoded>
			<wfw:commentRss>http://epicgeeks.net/updates/feed/</wfw:commentRss>
		<slash:comments>33</slash:comments>
		</item>
		<item>
		<title>Peek at FalloutQt</title>
		<link>http://epicgeeks.net/peek-at-falloutqt/</link>
		<comments>http://epicgeeks.net/peek-at-falloutqt/#comments</comments>
		<pubDate>Tue, 31 May 2011 17:25:58 +0000</pubDate>
		<dc:creator>J. Newing</dc:creator>
				<category><![CDATA[FalloutQt]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://zeropair.com/?p=95</guid>
		<description><![CDATA[While FalloutQt did get pushed to the back for a bit it&#8217;s all but forgotten about, and with this here is a update, a of things to come. [youtube]http://www.youtube.com/watch?v=6cErrH2b_ac[/youtube] &#160;]]></description>
			<content:encoded><![CDATA[<p>While FalloutQt did get pushed to the back for a bit it&#8217;s all but forgotten about, and with this here is a update, a of things to come.</p>
<p>[youtube]http://www.youtube.com/watch?v=6cErrH2b_ac[/youtube]</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://epicgeeks.net/peek-at-falloutqt/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>STFS Block Busting</title>
		<link>http://epicgeeks.net/stfs-block-busting/</link>
		<comments>http://epicgeeks.net/stfs-block-busting/#comments</comments>
		<pubDate>Wed, 18 May 2011 17:51:07 +0000</pubDate>
		<dc:creator>J. Newing</dc:creator>
				<category><![CDATA[Misc.]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://zeropair.com/?p=86</guid>
		<description><![CDATA[So while playing around with the small block nands on the XBOX 360 I also decided it would be a good idea to expand my knowledge of the Secure Transfer File System (STFS) and created a nice c++ class that breaks out STFS files into &#8220;data blocks&#8221; and &#8220;hash blocks&#8221; at a size of 0&#215;1000 ...]]></description>
			<content:encoded><![CDATA[<p>So while playing around with the small block nands on the XBOX 360 I also decided it would be a good idea to expand my knowledge of the Secure Transfer File System (STFS) and created a nice c++ class that breaks out STFS files into &#8220;data blocks&#8221; and &#8220;hash blocks&#8221; at a size of 0&#215;1000 data bytes to 0&#215;18 hash bytes per each.</p>
<p>So each data block is stored in the data_blocks List withing the STFS class and that data blocks corresponding hash is stored within the hash_blocks List. (eg: data_block[0] would be a unsigned char[0x1000] and its corresponding unsigned char[0x18] hash would be in hash_blocks[0]) remembering that the hash block is 0&#215;18 bytes long where as the hash itself is only the first 0&#215;14 bytes.</p>
<p><span id="more-86"></span></p>
<p><strong>stfs.h</strong></p><pre class="crayon-plain-tag">#ifndef STFS_H
#define STFS_H

#include &amp;lt;QList&amp;gt;
#include &amp;lt;QByteArray&amp;gt;
#include &amp;lt;QString&amp;gt;
#include &amp;lt;QFile&amp;gt;
#include &amp;lt;QDebug&amp;gt;
#include &amp;lt;QCryptographicHash&amp;gt;
#include &amp;lt;QChar&amp;gt;

#define BLOCK 0x1000
#define HASH_BLOCK 0x18
#define HASH 0x14
#define DATA_START 0xC000
#define TABLE0 0xA000
#define TABLE1 0xB8000
#define MASTER_TABLE 0xB6000    // master table

class STFS
{
public:
    QByteArray origional;
    QList&amp;lt;QByteArray&amp;gt; stfs_blocks, data_blocks, hash_blocks, master_table;

    STFS();
    STFS(const QByteArray&amp;amp; stfsdata);

    ~STFS();

    void Init(const QByteArray&amp;amp; stfsdata);
    void ValidBlock(int xBlock);
    void ValidMaster();
    QByteArray ReadBlock(int xBlock);
    void FixBlockHash(int xBlock);
    bool isHashBlock(int xBlock);
    void BlockPadding(QByteArray&amp;amp; blockdata);
    QByteArray ExtractFile(const char* filename);
    QByteArray ReplaceFile(const QByteArray&amp;amp; filedata);

private:

};

#endif // STFS_H</pre><p>&nbsp;</p>
<p><strong>stfs.cpp</strong></p><pre class="crayon-plain-tag">#include &quot;stfs.h&quot;

STFS::STFS()
{
}

STFS::STFS(const QByteArray &amp;amp;stfsdata)
{
    Init(stfsdata);
}

STFS::~STFS()
{
}

void STFS::Init(const QByteArray &amp;amp;stfsdata)
{
    // make a copy of the origional data
    origional = stfsdata;

    // Break the file into blocks
    for (int x = 0xC; x &amp;lt; (stfsdata.size() / BLOCK); x++)
    {
        stfs_blocks.push_back( stfsdata.mid((x * BLOCK), BLOCK) );
    }

    // read table 0 into hashs
    for (int x = 0; x &amp;lt; (BLOCK / HASH_BLOCK); x++)
    {
        hash_blocks.push_back( stfsdata.mid((x * HASH_BLOCK) + TABLE0, HASH_BLOCK) );
    }

    // remove crap and leave DATA BLOCKS ONLY
    for (int x = 0; x &amp;lt; stfs_blocks.size(); x++)
    {
        if (isHashBlock(x))
        {
            if ((x * BLOCK) + DATA_START != MASTER_TABLE)
            {
                for (int y = 0; y &amp;lt; (BLOCK / HASH_BLOCK); y++)
                {
                    hash_blocks.push_back( stfs_blocks[x].mid((y * HASH_BLOCK), HASH_BLOCK) );
                }
            }

            x++;
        }
        else
        {
            data_blocks.push_back(stfs_blocks[x]);
        }
    }

    // read the master table
    for (int x = 0; x &amp;lt; (BLOCK / HASH_BLOCK); x++)
    {
        master_table.push_back( stfsdata.mid((x * HASH_BLOCK) + MASTER_TABLE, HASH_BLOCK) );
    }
}

void STFS::ValidBlock(int xBlock)
{

    QByteArray calcd_hash = QCryptographicHash::hash(data_blocks[xBlock], QCryptographicHash::Sha1);

    qDebug() &amp;lt;&amp;lt; &quot;Block: &quot; &amp;lt;&amp;lt; hex &amp;lt;&amp;lt; (xBlock + 0xC) &amp;lt;&amp;lt; &quot; Offset: &quot; &amp;lt;&amp;lt; hex &amp;lt;&amp;lt; ((xBlock) * BLOCK) + DATA_START;
    qDebug() &amp;lt;&amp;lt; &quot;Current Hash: &quot; &amp;lt;&amp;lt; hash_blocks[xBlock].mid(0, 0x14).toHex();
    qDebug() &amp;lt;&amp;lt; &quot;Cacled Hash: &quot; &amp;lt;&amp;lt; calcd_hash.toHex();

    if (calcd_hash == hash_blocks[xBlock].mid(0, 0x14))
        qDebug() &amp;lt;&amp;lt; &quot;Valid: TRUE&quot;;
    else
        qDebug() &amp;lt;&amp;lt; &quot;Valid: FALSE&quot;;

    qDebug();
}

void STFS::ValidMaster()
{
    // hash calc the block
    QByteArray pblock;

    for (int x = 0; x &amp;lt; (BLOCK / HASH_BLOCK); x++)
        pblock.append(hash_blocks[x]);

    // pad out the pblock
    BlockPadding(pblock);

    QByteArray hash = QCryptographicHash::hash(pblock, QCryptographicHash::Sha1);

    qDebug() &amp;lt;&amp;lt; &quot;Caled Hash: &quot; &amp;lt;&amp;lt; hash.toHex();
    qDebug() &amp;lt;&amp;lt; &quot;Master Table: &quot; &amp;lt;&amp;lt; master_table[0].left(0x14).toHex();
}

QByteArray STFS::ReadBlock(int xBlock)
{
    return data_blocks.at(xBlock);
}

void STFS::FixBlockHash(int xBlock)
{
    hash_blocks[xBlock].append( QCryptographicHash::hash(data_blocks[xBlock], QCryptographicHash::Sha1) );
}

bool STFS::isHashBlock(int xBlock)
{
    int block_offset = (xBlock * BLOCK) + DATA_START;

    if (block_offset == MASTER_TABLE)
        return TRUE;

    if (xBlock % 0xAC == 0 &amp;amp;&amp;amp; xBlock &amp;gt; 0)
    {
        return TRUE;
    }

    return FALSE;
}

void STFS::BlockPadding(QByteArray &amp;amp;blockdata)
{
    int npadding = BLOCK - blockdata.size();

    for (int x = (BLOCK - npadding); x &amp;lt; BLOCK; x++)
        blockdata.append(QChar(0x00));

}</pre><p></p>
]]></content:encoded>
			<wfw:commentRss>http://epicgeeks.net/stfs-block-busting/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>16mb Nand Layout</title>
		<link>http://epicgeeks.net/16mb-nand-layout/</link>
		<comments>http://epicgeeks.net/16mb-nand-layout/#comments</comments>
		<pubDate>Fri, 13 May 2011 02:23:35 +0000</pubDate>
		<dc:creator>J. Newing</dc:creator>
				<category><![CDATA[Misc.]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://zeropair.com/?p=82</guid>
		<description><![CDATA[So I&#8217;ve been able to write an app that extracts and decrypts the following from a XBOX 360 nand image. SMC KeyVault BootLoaders (CB, CD, CE, CF, CG) Flash Filesystem etc&#8230; For testing purposed I checked all my extracts against the ones created by 360 Flash Tool v0.97 (created by Robinsod, TheSpecialist and SeventhSon) every ...]]></description>
			<content:encoded><![CDATA[<p>So I&#8217;ve been able to write an app that extracts and decrypts the following from a XBOX 360 nand image.</p>
<ul>
<li>SMC</li>
<li>KeyVault</li>
<li>BootLoaders (CB, CD, CE, CF, CG)</li>
<li>Flash Filesystem etc&#8230;</li>
</ul>
<p>For testing purposed I checked all my extracts against the ones created by 360 Flash Tool v0.97 (created by Robinsod, TheSpecialist and SeventhSon) every one matched byte for byte except my damn CD :s for some reason my CD  the first 0xf0 bytes matched exactly then the next 0&#215;110 would be different, however then the next 0xf0 would match again etc.. this continues on until EOF is reached (as witch the last 0xf0 bytes are matching :s)</p>
<p>My only guess is this has something to do with me not breaking the file down into 0&#215;4000 byte sections and treating each 0&#215;4000 bytes as a data block. Nands are nasty little creatures! If anyone knows anything about the layout of the XBOX 360 nand image please feel free to comment me on here as I would like to hear from you.</p>
]]></content:encoded>
			<wfw:commentRss>http://epicgeeks.net/16mb-nand-layout/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Breaking From Qt</title>
		<link>http://epicgeeks.net/breaking-from-qt/</link>
		<comments>http://epicgeeks.net/breaking-from-qt/#comments</comments>
		<pubDate>Mon, 09 May 2011 23:51:00 +0000</pubDate>
		<dc:creator>J. Newing</dc:creator>
				<category><![CDATA[Misc.]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://zeropair.com/?p=79</guid>
		<description><![CDATA[So I&#8217;ve decided to take a little break from development on Qt and check out some other areas of interest, more specifically freeboot images and nand layouts. I&#8217;ve been learning lots and finding all kinds of interesting information. I figured a good way to start was to see if I can take a full nand ...]]></description>
			<content:encoded><![CDATA[<p>So I&#8217;ve decided to take a little break from development on Qt and check out some other areas of interest, more specifically freeboot images and nand layouts. I&#8217;ve been learning lots and finding all kinds of interesting information. I figured a good way to start was to see if I can take a full nand image and extract / decrypt all the useful sections that most nand programs do.</p>
<p>So far I&#8217;ve been able to extract and decrypt the SMC (Southbridge) that was interesting! If people are interested I would be happy to post the code. Also if anyone has any advice or knows what they are doing drop me a line if you don&#8217;t mind answering some questions.</p>
]]></content:encoded>
			<wfw:commentRss>http://epicgeeks.net/breaking-from-qt/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
