PageRenderTime 27ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/classes/crypt.html

https://github.com/sublimeowl/docs
HTML | 186 lines | 174 code | 12 blank | 0 comment | 0 complexity | 78f91fa2a31008577cc5b1f1ed433764 MD5 | raw file
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>Crypt Class - Fuel Documentation</title>
  6. <link href="../assets/css/main.css" media="screen" rel="stylesheet" />
  7. <script type="text/javascript" src="../assets/js/jquery-1.4.4.min.js"></script>
  8. <script type="text/javascript" src="../assets/js/nav.js"></script>
  9. <script type="text/javascript" src="../assets/js/highlight.pack.js"></script>
  10. <script type="text/javascript">
  11. $(function() {
  12. show_nav('classes', '../');
  13. });
  14. hljs.tabReplace = ' ';
  15. hljs.initHighlightingOnLoad();
  16. </script>
  17. </head>
  18. <body>
  19. <header>
  20. <h1>Fuel Documentation</h1>
  21. </header>
  22. <div id="main-nav"></div>
  23. <section id="content">
  24. <h2>Crypt Class</h2>
  25. <p>
  26. The Crypt class allows encrypt or decrypt a string. The Crypt class is also used internally by for example the Fuel Sessions class.
  27. </p>
  28. <p>It uses the encryption and hashing methods provided by PHPSecLib, so it's not dependent on external modules being available, such as mcrypt.</p>
  29. <section>
  30. <h2>Configuration</h2>
  31. <p>
  32. The Crypt class is configured through the <kbd>app/config/crypt.php</kbd> configuration file. It will be generated and populated with random values when you first use the Crypt class or if one of the required configuration values is missing.
  33. </p>
  34. <p class="note">
  35. Note that this will require write access to app/config/crypt.php! If this is not possible, make sure all configuration settings are set!
  36. </p>
  37. <p>The following configuration settings can be defined:</p>
  38. <table class="config">
  39. <tbody>
  40. <tr class="header">
  41. <th>Param</th>
  42. <th>Type</th>
  43. <th>Default</th>
  44. <th>Description</th>
  45. </tr>
  46. <tr>
  47. <th>crypto_key</th>
  48. <td>string</td>
  49. <td>n/a</td>
  50. <td>
  51. Random encryption key value used in the encryption routines. Make sure you set this to something unique and random!
  52. </td>
  53. </tr>
  54. <tr>
  55. <th>crypto_iv</th>
  56. <td>string</td>
  57. <td>n/a</td>
  58. <td>
  59. Random encryption initialisation vector used in the encryption routines. Make sure you set this to something unique and random!
  60. </td>
  61. </tr>
  62. <tr>
  63. <th>crypto_hmac</th>
  64. <td>string</td>
  65. <td>n/a</td>
  66. <td>
  67. Random value used in the Hash-based Message Authentication Code (HMAC) routines. Make sure you set this to something unique and random!
  68. </td>
  69. </tr>
  70. </tbody>
  71. </table>
  72. <p class="note">
  73. If you assign keys manually, note that they are base64_encoded, and the length must be a multiple of 4 to be able to decode it. Make sure the length is correct!
  74. </p>
  75. </section>
  76. <article>
  77. <h4 id="method_encode">encode($value, $key = false)</h4>
  78. <p>The <strong>encode</strong> method encrypts a string value, optionally with a custom encryption key.</p>
  79. <table class="method">
  80. <tbody>
  81. <tr>
  82. <th class="legend">Static</th>
  83. <td>No</td>
  84. </tr>
  85. <tr>
  86. <th>Parameters</th>
  87. <td>
  88. <table class="parameters">
  89. <tr>
  90. <th>Param</th>
  91. <th>Default</th>
  92. <th class="description">Description</th>
  93. </tr>
  94. <tr>
  95. <th><kbd>$value</kbd></th>
  96. <td><i>Required</i></td>
  97. <td>String value to encode.</td>
  98. </tr>
  99. <tr>
  100. <th><kbd>$key</kbd></th>
  101. <td><pre class="php"><code>false</code></pre></td>
  102. <td>Optional custom key value to be used to encode the value passsed. If false, the config value '<strong>crypto_key</strong>' is used.</td>
  103. </tr>
  104. </table>
  105. </td>
  106. </tr>
  107. <tr>
  108. <th>Returns</th>
  109. <td>string</td>
  110. </tr>
  111. <tr>
  112. <th>Example</th>
  113. <td>
  114. <pre class="php"><code>// encode a variable with a custom key
  115. $value = Crypt::encode($value, 'R@nd0mK~Y');</code></pre>
  116. </td>
  117. </tr>
  118. </tbody>
  119. </table>
  120. </article>
  121. <article>
  122. <h4 id="method_decode">decode($value, $key = false)</h4>
  123. <p>The <strong>decode</strong> method decrypts a string value, optionally with a custom key.</p>
  124. <table class="method">
  125. <tbody>
  126. <tr>
  127. <th class="legend">Static</th>
  128. <td>No</td>
  129. </tr>
  130. <tr>
  131. <th>Parameters</th>
  132. <td>
  133. <table class="parameters">
  134. <tr>
  135. <th>Param</th>
  136. <th>Default</th>
  137. <th class="description">Description</th>
  138. </tr>
  139. <tr>
  140. <th><kbd>$value</kbd></th>
  141. <td><i>Required</i></td>
  142. <td>String value to decode.</td>
  143. </tr>
  144. <tr>
  145. <th><kbd>$key</kbd></th>
  146. <td><pre class="php"><code>false</code></pre></td>
  147. <td>Optional custom key value to be used to decode the value passsed. If false, the config value '<strong>crypto_key</strong>' is used.</td>
  148. </tr>
  149. </table>
  150. </td>
  151. </tr>
  152. <tr>
  153. <th>Returns</th>
  154. <td>mixed - String value with the decoded value, or <kbd>false</kbd> if the value could not be decoded.</td>
  155. </tr>
  156. <tr>
  157. <th>Example</th>
  158. <td>
  159. <pre class="php"><code>// decode a variable with a custom key
  160. $value = Crypt::decode($value, 'R@nd0mK~Y');</code></pre>
  161. </td>
  162. </tr>
  163. </tbody>
  164. </table>
  165. </article>
  166. </section>
  167. <section id="footer">
  168. <p>
  169. <a href="http://fuelphp.com">Fuel</a> is released under the MIT license.<br />
  170. &copy; 2010 - 2011 Fuel Development Team
  171. </p>
  172. </section>
  173. </body>
  174. </html>