Andrey Andreev | c576995 | 2019-01-16 17:49:35 +0200 | [diff] [blame] | 1 | |
| 2 | |
| 3 | <!DOCTYPE html> |
| 4 | <!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]--> |
| 5 | <!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]--> |
| 6 | <head> |
| 7 | <meta charset="utf-8"> |
| 8 | <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| 9 | |
| 10 | <title>Encryption Library — CodeIgniter 3.1.10 documentation</title> |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | <link rel="shortcut icon" href="../_static/ci-icon.ico"/> |
| 16 | |
| 17 | |
| 18 | |
| 19 | <link href='https://fonts.googleapis.com/css?family=Lato:400,700,400italic,700italic|Roboto+Slab:400,700|Inconsolata:400,700&subset=latin,cyrillic' rel='stylesheet' type='text/css'> |
| 20 | |
| 21 | |
| 22 | |
| 23 | |
| 24 | |
| 25 | |
| 26 | |
| 27 | |
| 28 | |
| 29 | <link rel="stylesheet" href="../_static/css/citheme.css" type="text/css" /> |
| 30 | |
| 31 | |
| 32 | |
| 33 | <link rel="index" title="Index" |
| 34 | href="../genindex.html"/> |
| 35 | <link rel="search" title="Search" href="../search.html"/> |
| 36 | <link rel="top" title="CodeIgniter 3.1.10 documentation" href="../index.html"/> |
| 37 | <link rel="up" title="Libraries" href="index.html"/> |
| 38 | <link rel="next" title="File Uploading Class" href="file_uploading.html"/> |
| 39 | <link rel="prev" title="Encrypt Class" href="encrypt.html"/> |
| 40 | |
| 41 | |
| 42 | <script src="https://cdnjs.cloudflare.com/ajax/libs/modernizr/2.6.2/modernizr.min.js"></script> |
| 43 | |
| 44 | </head> |
| 45 | |
| 46 | <body class="wy-body-for-nav" role="document"> |
| 47 | |
| 48 | <div id="nav"> |
| 49 | <div id="nav_inner"> |
| 50 | |
| 51 | |
| 52 | |
| 53 | <div id="pulldown-menu" class="ciNav"> |
| 54 | <ul> |
| 55 | <li class="toctree-l1"><a class="reference internal" href="../general/welcome.html">Welcome to CodeIgniter</a></li> |
| 56 | </ul> |
| 57 | <ul> |
| 58 | <li class="toctree-l1"><a class="reference internal" href="../installation/index.html">Installation Instructions</a><ul> |
| 59 | <li class="toctree-l2"><a class="reference internal" href="../installation/downloads.html">Downloading CodeIgniter</a></li> |
| 60 | <li class="toctree-l2"><a class="reference internal" href="../installation/index.html">Installation Instructions</a></li> |
| 61 | <li class="toctree-l2"><a class="reference internal" href="../installation/upgrading.html">Upgrading From a Previous Version</a></li> |
| 62 | <li class="toctree-l2"><a class="reference internal" href="../installation/troubleshooting.html">Troubleshooting</a></li> |
| 63 | </ul> |
| 64 | </li> |
| 65 | </ul> |
| 66 | <ul> |
| 67 | <li class="toctree-l1"><a class="reference internal" href="../overview/index.html">CodeIgniter Overview</a><ul> |
| 68 | <li class="toctree-l2"><a class="reference internal" href="../overview/getting_started.html">Getting Started</a></li> |
| 69 | <li class="toctree-l2"><a class="reference internal" href="../overview/at_a_glance.html">CodeIgniter at a Glance</a></li> |
| 70 | <li class="toctree-l2"><a class="reference internal" href="../overview/features.html">Supported Features</a></li> |
| 71 | <li class="toctree-l2"><a class="reference internal" href="../overview/appflow.html">Application Flow Chart</a></li> |
| 72 | <li class="toctree-l2"><a class="reference internal" href="../overview/mvc.html">Model-View-Controller</a></li> |
| 73 | <li class="toctree-l2"><a class="reference internal" href="../overview/goals.html">Architectural Goals</a></li> |
| 74 | </ul> |
| 75 | </li> |
| 76 | </ul> |
| 77 | <ul> |
| 78 | <li class="toctree-l1"><a class="reference internal" href="../tutorial/index.html">Tutorial</a><ul> |
| 79 | <li class="toctree-l2"><a class="reference internal" href="../tutorial/static_pages.html">Static pages</a></li> |
| 80 | <li class="toctree-l2"><a class="reference internal" href="../tutorial/news_section.html">News section</a></li> |
| 81 | <li class="toctree-l2"><a class="reference internal" href="../tutorial/create_news_items.html">Create news items</a></li> |
| 82 | <li class="toctree-l2"><a class="reference internal" href="../tutorial/conclusion.html">Conclusion</a></li> |
| 83 | </ul> |
| 84 | </li> |
| 85 | </ul> |
| 86 | <ul> |
| 87 | <li class="toctree-l1"><a class="reference internal" href="../contributing/index.html">Contributing to CodeIgniter</a><ul> |
| 88 | <li class="toctree-l2"><a class="reference internal" href="../documentation/index.html">Writing CodeIgniter Documentation</a></li> |
| 89 | <li class="toctree-l2"><a class="reference internal" href="../DCO.html">Developer’s Certificate of Origin 1.1</a></li> |
| 90 | </ul> |
| 91 | </li> |
| 92 | </ul> |
| 93 | <ul> |
| 94 | <li class="toctree-l1"><a class="reference internal" href="../general/index.html">General Topics</a><ul> |
| 95 | <li class="toctree-l2"><a class="reference internal" href="../general/urls.html">CodeIgniter URLs</a></li> |
| 96 | <li class="toctree-l2"><a class="reference internal" href="../general/controllers.html">Controllers</a></li> |
| 97 | <li class="toctree-l2"><a class="reference internal" href="../general/reserved_names.html">Reserved Names</a></li> |
| 98 | <li class="toctree-l2"><a class="reference internal" href="../general/views.html">Views</a></li> |
| 99 | <li class="toctree-l2"><a class="reference internal" href="../general/models.html">Models</a></li> |
| 100 | <li class="toctree-l2"><a class="reference internal" href="../general/helpers.html">Helpers</a></li> |
| 101 | <li class="toctree-l2"><a class="reference internal" href="../general/libraries.html">Using CodeIgniter Libraries</a></li> |
| 102 | <li class="toctree-l2"><a class="reference internal" href="../general/creating_libraries.html">Creating Libraries</a></li> |
| 103 | <li class="toctree-l2"><a class="reference internal" href="../general/drivers.html">Using CodeIgniter Drivers</a></li> |
| 104 | <li class="toctree-l2"><a class="reference internal" href="../general/creating_drivers.html">Creating Drivers</a></li> |
| 105 | <li class="toctree-l2"><a class="reference internal" href="../general/core_classes.html">Creating Core System Classes</a></li> |
| 106 | <li class="toctree-l2"><a class="reference internal" href="../general/ancillary_classes.html">Creating Ancillary Classes</a></li> |
| 107 | <li class="toctree-l2"><a class="reference internal" href="../general/hooks.html">Hooks - Extending the Framework Core</a></li> |
| 108 | <li class="toctree-l2"><a class="reference internal" href="../general/autoloader.html">Auto-loading Resources</a></li> |
| 109 | <li class="toctree-l2"><a class="reference internal" href="../general/common_functions.html">Common Functions</a></li> |
| 110 | <li class="toctree-l2"><a class="reference internal" href="../general/compatibility_functions.html">Compatibility Functions</a></li> |
| 111 | <li class="toctree-l2"><a class="reference internal" href="../general/routing.html">URI Routing</a></li> |
| 112 | <li class="toctree-l2"><a class="reference internal" href="../general/errors.html">Error Handling</a></li> |
| 113 | <li class="toctree-l2"><a class="reference internal" href="../general/caching.html">Caching</a></li> |
| 114 | <li class="toctree-l2"><a class="reference internal" href="../general/profiling.html">Profiling Your Application</a></li> |
| 115 | <li class="toctree-l2"><a class="reference internal" href="../general/cli.html">Running via the CLI</a></li> |
| 116 | <li class="toctree-l2"><a class="reference internal" href="../general/managing_apps.html">Managing your Applications</a></li> |
| 117 | <li class="toctree-l2"><a class="reference internal" href="../general/environments.html">Handling Multiple Environments</a></li> |
| 118 | <li class="toctree-l2"><a class="reference internal" href="../general/alternative_php.html">Alternate PHP Syntax for View Files</a></li> |
| 119 | <li class="toctree-l2"><a class="reference internal" href="../general/security.html">Security</a></li> |
| 120 | <li class="toctree-l2"><a class="reference internal" href="../general/styleguide.html">PHP Style Guide</a></li> |
| 121 | </ul> |
| 122 | </li> |
| 123 | </ul> |
| 124 | <ul class="current"> |
| 125 | <li class="toctree-l1 current"><a class="reference internal" href="index.html">Libraries</a><ul class="current"> |
| 126 | <li class="toctree-l2"><a class="reference internal" href="benchmark.html">Benchmarking Class</a></li> |
| 127 | <li class="toctree-l2"><a class="reference internal" href="caching.html">Caching Driver</a></li> |
| 128 | <li class="toctree-l2"><a class="reference internal" href="calendar.html">Calendaring Class</a></li> |
| 129 | <li class="toctree-l2"><a class="reference internal" href="cart.html">Shopping Cart Class</a></li> |
| 130 | <li class="toctree-l2"><a class="reference internal" href="config.html">Config Class</a></li> |
| 131 | <li class="toctree-l2"><a class="reference internal" href="email.html">Email Class</a></li> |
| 132 | <li class="toctree-l2"><a class="reference internal" href="encrypt.html">Encrypt Class</a></li> |
| 133 | <li class="toctree-l2 current"><a class="current reference internal" href="#">Encryption Library</a></li> |
| 134 | <li class="toctree-l2"><a class="reference internal" href="file_uploading.html">File Uploading Class</a></li> |
| 135 | <li class="toctree-l2"><a class="reference internal" href="form_validation.html">Form Validation</a></li> |
| 136 | <li class="toctree-l2"><a class="reference internal" href="ftp.html">FTP Class</a></li> |
| 137 | <li class="toctree-l2"><a class="reference internal" href="image_lib.html">Image Manipulation Class</a></li> |
| 138 | <li class="toctree-l2"><a class="reference internal" href="input.html">Input Class</a></li> |
| 139 | <li class="toctree-l2"><a class="reference internal" href="javascript.html">Javascript Class</a></li> |
| 140 | <li class="toctree-l2"><a class="reference internal" href="language.html">Language Class</a></li> |
| 141 | <li class="toctree-l2"><a class="reference internal" href="loader.html">Loader Class</a></li> |
| 142 | <li class="toctree-l2"><a class="reference internal" href="migration.html">Migrations Class</a></li> |
| 143 | <li class="toctree-l2"><a class="reference internal" href="output.html">Output Class</a></li> |
| 144 | <li class="toctree-l2"><a class="reference internal" href="pagination.html">Pagination Class</a></li> |
| 145 | <li class="toctree-l2"><a class="reference internal" href="parser.html">Template Parser Class</a></li> |
| 146 | <li class="toctree-l2"><a class="reference internal" href="security.html">Security Class</a></li> |
| 147 | <li class="toctree-l2"><a class="reference internal" href="sessions.html">Session Library</a></li> |
| 148 | <li class="toctree-l2"><a class="reference internal" href="table.html">HTML Table Class</a></li> |
| 149 | <li class="toctree-l2"><a class="reference internal" href="trackback.html">Trackback Class</a></li> |
| 150 | <li class="toctree-l2"><a class="reference internal" href="typography.html">Typography Class</a></li> |
| 151 | <li class="toctree-l2"><a class="reference internal" href="unit_testing.html">Unit Testing Class</a></li> |
| 152 | <li class="toctree-l2"><a class="reference internal" href="uri.html">URI Class</a></li> |
| 153 | <li class="toctree-l2"><a class="reference internal" href="user_agent.html">User Agent Class</a></li> |
| 154 | <li class="toctree-l2"><a class="reference internal" href="xmlrpc.html">XML-RPC and XML-RPC Server Classes</a></li> |
| 155 | <li class="toctree-l2"><a class="reference internal" href="zip.html">Zip Encoding Class</a></li> |
| 156 | </ul> |
| 157 | </li> |
| 158 | </ul> |
| 159 | <ul> |
| 160 | <li class="toctree-l1"><a class="reference internal" href="../database/index.html">Database Reference</a><ul> |
| 161 | <li class="toctree-l2"><a class="reference internal" href="../database/examples.html">Quick Start: Usage Examples</a></li> |
| 162 | <li class="toctree-l2"><a class="reference internal" href="../database/configuration.html">Database Configuration</a></li> |
| 163 | <li class="toctree-l2"><a class="reference internal" href="../database/connecting.html">Connecting to a Database</a></li> |
| 164 | <li class="toctree-l2"><a class="reference internal" href="../database/queries.html">Running Queries</a></li> |
| 165 | <li class="toctree-l2"><a class="reference internal" href="../database/results.html">Generating Query Results</a></li> |
| 166 | <li class="toctree-l2"><a class="reference internal" href="../database/helpers.html">Query Helper Functions</a></li> |
| 167 | <li class="toctree-l2"><a class="reference internal" href="../database/query_builder.html">Query Builder Class</a></li> |
| 168 | <li class="toctree-l2"><a class="reference internal" href="../database/transactions.html">Transactions</a></li> |
| 169 | <li class="toctree-l2"><a class="reference internal" href="../database/metadata.html">Getting MetaData</a></li> |
| 170 | <li class="toctree-l2"><a class="reference internal" href="../database/call_function.html">Custom Function Calls</a></li> |
| 171 | <li class="toctree-l2"><a class="reference internal" href="../database/caching.html">Query Caching</a></li> |
| 172 | <li class="toctree-l2"><a class="reference internal" href="../database/forge.html">Database Manipulation with Database Forge</a></li> |
| 173 | <li class="toctree-l2"><a class="reference internal" href="../database/utilities.html">Database Utilities Class</a></li> |
| 174 | <li class="toctree-l2"><a class="reference internal" href="../database/db_driver_reference.html">Database Driver Reference</a></li> |
| 175 | </ul> |
| 176 | </li> |
| 177 | </ul> |
| 178 | <ul> |
| 179 | <li class="toctree-l1"><a class="reference internal" href="../helpers/index.html">Helpers</a><ul> |
| 180 | <li class="toctree-l2"><a class="reference internal" href="../helpers/array_helper.html">Array Helper</a></li> |
| 181 | <li class="toctree-l2"><a class="reference internal" href="../helpers/captcha_helper.html">CAPTCHA Helper</a></li> |
| 182 | <li class="toctree-l2"><a class="reference internal" href="../helpers/cookie_helper.html">Cookie Helper</a></li> |
| 183 | <li class="toctree-l2"><a class="reference internal" href="../helpers/date_helper.html">Date Helper</a></li> |
| 184 | <li class="toctree-l2"><a class="reference internal" href="../helpers/directory_helper.html">Directory Helper</a></li> |
| 185 | <li class="toctree-l2"><a class="reference internal" href="../helpers/download_helper.html">Download Helper</a></li> |
| 186 | <li class="toctree-l2"><a class="reference internal" href="../helpers/email_helper.html">Email Helper</a></li> |
| 187 | <li class="toctree-l2"><a class="reference internal" href="../helpers/file_helper.html">File Helper</a></li> |
| 188 | <li class="toctree-l2"><a class="reference internal" href="../helpers/form_helper.html">Form Helper</a></li> |
| 189 | <li class="toctree-l2"><a class="reference internal" href="../helpers/html_helper.html">HTML Helper</a></li> |
| 190 | <li class="toctree-l2"><a class="reference internal" href="../helpers/inflector_helper.html">Inflector Helper</a></li> |
| 191 | <li class="toctree-l2"><a class="reference internal" href="../helpers/language_helper.html">Language Helper</a></li> |
| 192 | <li class="toctree-l2"><a class="reference internal" href="../helpers/number_helper.html">Number Helper</a></li> |
| 193 | <li class="toctree-l2"><a class="reference internal" href="../helpers/path_helper.html">Path Helper</a></li> |
| 194 | <li class="toctree-l2"><a class="reference internal" href="../helpers/security_helper.html">Security Helper</a></li> |
| 195 | <li class="toctree-l2"><a class="reference internal" href="../helpers/smiley_helper.html">Smiley Helper</a></li> |
| 196 | <li class="toctree-l2"><a class="reference internal" href="../helpers/string_helper.html">String Helper</a></li> |
| 197 | <li class="toctree-l2"><a class="reference internal" href="../helpers/text_helper.html">Text Helper</a></li> |
| 198 | <li class="toctree-l2"><a class="reference internal" href="../helpers/typography_helper.html">Typography Helper</a></li> |
| 199 | <li class="toctree-l2"><a class="reference internal" href="../helpers/url_helper.html">URL Helper</a></li> |
| 200 | <li class="toctree-l2"><a class="reference internal" href="../helpers/xml_helper.html">XML Helper</a></li> |
| 201 | </ul> |
| 202 | </li> |
| 203 | </ul> |
| 204 | |
| 205 | </div> |
| 206 | |
| 207 | |
| 208 | </div> |
| 209 | </div> |
| 210 | <div id="nav2"> |
| 211 | <a href="#" id="openToc"> |
| 212 | <img src="data:image/jpeg;base64,/9j/4AAQSkZJRgABAgAAZABkAAD/7AARRHVja3kAAQAEAAAARgAA/+4ADkFkb2JlAGTAAAAAAf/bAIQABAMDAwMDBAMDBAYEAwQGBwUEBAUHCAYGBwYGCAoICQkJCQgKCgwMDAwMCgwMDQ0MDBERERERFBQUFBQUFBQUFAEEBQUIBwgPCgoPFA4ODhQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQU/8AAEQgAKwCaAwERAAIRAQMRAf/EAHsAAQAABwEBAAAAAAAAAAAAAAABAwQFBgcIAgkBAQAAAAAAAAAAAAAAAAAAAAAQAAEDAwICBwYEAgsAAAAAAAIBAwQAEQUSBiEHkROTVNQWGDFBUVIUCHEiMtOUFWGBobHRQlMkZIRVEQEAAAAAAAAAAAAAAAAAAAAA/9oADAMBAAIRAxEAPwDSC+ygkOOaUoKigUCgUCgUCgUCgUCgUCgUCgkuGguIP9FBMFb0Hqg7We+3jlmIqqYFf4ub+/QYlnOR/LqIBKGFUbf8qWv971BytQXXE7Y3Lnm3HsFhp2TaZJAdchRXpIgSpdEJWxJEW3xoKV7F5OMy7JkQn2o7D6w33XGjEAkoiqrJEqIiOIiKuhePCgqp22dyYyS3CyWHnQ5joG61HkRnmnTbaFSMhExRVQRRVJU9iUHjE7ez+fJ0MFipmUNhBV8YUd2SoIV9KkjQla9ltegttBdPLW4/qocL+UTfrMiHW4+P9M71shuyrqaHTcxsl7jegpsji8nh5ZwMvDfgTm0RTjSmjYdFCS6KoOIipdFunCgmNYTMv457MMY6U7iI6oMieDDhRm1VbIhuoOkbqtuK0Hpzb+eZcYZexUxt6UyUqK2cd0SdjtgrhOgijcgERUlJOCIl6CpgbP3blRI8XgMjNARAyKNDfeRBdFDBVUAXgQrqH4pxoJTu2NysY97LP4ac1io5q1InHFeGO24LnVKJuKOkSQ/yKir+rh7aCLG1dzypZQI2FnvTgccYOM3FeN0XWERXAUEFVQgQkUktdLpegm+Td3/Xli/L+S/mYNJIOF9G/wBeLKrZHFb0akG6W1WtQWSg3Dyg5e7V3fipE3O4/wCrktyzYA+ufas2LbZIlmnAT2kvuoN1wft95augilglX/tzP3qCu9O3LL/wV/i5v79BvmTADq14UGu91467Z6U9y0HzH/ncj/U/sT/CgynZG7I2NezpZGUjIycJkYkZSG+uQ81pbBNKLxJfjwoMqZ3/ALYHl35AJ7/cuwHcu5k7r1Q5pHetBjquqVVJWGxj9Zrtcl/Ggy3dHMvauR3HFZj5nHNxSyW5JISYDMoIwx8tFIGHZhPNaykGapr6rUAiicEoMG21lMRj8buPAz8xhJrr7uOeiPTCyAwXUaGR1mgozbTusOsFLEiJ7fbQa/h7gcjy2H3V6xppwDNtUSxCJIqp7valBuWVzJ22xuCROXNNZiJkMtms0DbjUkAZjzoDrTMd9dDRI44ZC2YsrYdKWP2WDT2S3N9dNdlRYrGMYc06IURXSYb0igrpWS485xVNS6nF4rwslkoMwnbpgZLB7bmt5uMweAhDEl4B5uSLzzqTnnyVpW2jaJHRMSIjdDiiotvy3DOE5rYTEbkl5yFn28k7JyG4c7AU2HtLH1uKfaiMPI40CdYbpNtmLdwTSn5rewLNld+7TLdeal4WarWBkbVKBjgdElMJJwAAY5fl4kB3b1fp4XvagsGS3FjJfLzDNtS8aeXx7LzT7TyzByQE5PccRGRC0ZRUDRV6y62vbjagzLmJzS2vuPK43JY6aP1TW6Jz+RIWyFtyC06y3EkiiinAo7YCqfq1AqqnGgsOH3lhZO8d1pmcpB8j5XIm9OYlBJSQ/FSS4427DKO0RC8AlcEMhFdViRR1WDWR5t3WXVuL1d106kG9vdeye2g60+1FDyW0shIcXVpyroXt8I8dfd+NB1vioAdWnD3UF1+gD4UFc6CEKpagxXN43rwJLUHz7yX2c8zokt9uHlsPIhA4aRnnHJTLptIS6CNsY7iASpxUUMkReGpfbQW0vtN5pitvrsN28rwtBD0nc0+/Yft5XhaB6TuaXfsP28rwtA9J3NPv2H7eV4Wgek7mn37D9vK8LQPSdzT79h+3leFoHpO5pd+w/byvC0D0nc0u/Yft5XhaB6TuaXfsP28rwtA9J3NLv2H7eV4Wgek7ml37D9vK8LQPSdzS79h+3leFoHpO5p9+w/byvC0E9r7Reazy2HIYVPxkS/CUHVn26cosxyv2g7h89LYmZSXOenvLEQ1YaQ222RATcQCP8rSGqqA8S02W2pQ6FhMoAIlqCtsnwoCpdKClejI4i3Sgtb+GBxVuNBSFt1pV/RQefLjPyUDy4z8lA8uM/JQPLjPyUDy4z8lA8uM/JQPLjPyUDy4z8lA8uM/JQPLjPyUDy4z8lA8utJ/koJ7WCbBU/LQXOPAFq1koK8B0pag90CggtBBf6qB0UDooHRQOigdFA6KB0UDooHRQOigdFA6KB0UDooI0EaBQf//Z" title="Toggle Table of Contents" alt="Toggle Table of Contents" /> |
| 213 | </a> |
| 214 | </div> |
| 215 | |
| 216 | <div class="wy-grid-for-nav"> |
| 217 | |
| 218 | |
| 219 | <nav data-toggle="wy-nav-shift" class="wy-nav-side"> |
| 220 | <div class="wy-side-nav-search"> |
| 221 | |
| 222 | <a href="../index.html" class="fa fa-home"> CodeIgniter</a> |
| 223 | |
| 224 | |
| 225 | <div role="search"> |
| 226 | <form id="rtd-search-form" class="wy-form" action="../search.html" method="get"> |
| 227 | <input type="text" name="q" placeholder="Search docs" /> |
| 228 | <input type="hidden" name="check_keywords" value="yes" /> |
| 229 | <input type="hidden" name="area" value="default" /> |
| 230 | </form> |
| 231 | </div> |
| 232 | </div> |
| 233 | |
| 234 | <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation"> |
| 235 | |
| 236 | |
| 237 | |
| 238 | <ul> |
| 239 | <li class="toctree-l1"><a class="reference internal" href="../general/welcome.html">Welcome to CodeIgniter</a></li> |
| 240 | </ul> |
| 241 | <ul> |
| 242 | <li class="toctree-l1"><a class="reference internal" href="../installation/index.html">Installation Instructions</a><ul> |
| 243 | <li class="toctree-l2"><a class="reference internal" href="../installation/downloads.html">Downloading CodeIgniter</a></li> |
| 244 | <li class="toctree-l2"><a class="reference internal" href="../installation/index.html">Installation Instructions</a></li> |
| 245 | <li class="toctree-l2"><a class="reference internal" href="../installation/upgrading.html">Upgrading From a Previous Version</a></li> |
| 246 | <li class="toctree-l2"><a class="reference internal" href="../installation/troubleshooting.html">Troubleshooting</a></li> |
| 247 | </ul> |
| 248 | </li> |
| 249 | </ul> |
| 250 | <ul> |
| 251 | <li class="toctree-l1"><a class="reference internal" href="../overview/index.html">CodeIgniter Overview</a><ul> |
| 252 | <li class="toctree-l2"><a class="reference internal" href="../overview/getting_started.html">Getting Started</a></li> |
| 253 | <li class="toctree-l2"><a class="reference internal" href="../overview/at_a_glance.html">CodeIgniter at a Glance</a></li> |
| 254 | <li class="toctree-l2"><a class="reference internal" href="../overview/features.html">Supported Features</a></li> |
| 255 | <li class="toctree-l2"><a class="reference internal" href="../overview/appflow.html">Application Flow Chart</a></li> |
| 256 | <li class="toctree-l2"><a class="reference internal" href="../overview/mvc.html">Model-View-Controller</a></li> |
| 257 | <li class="toctree-l2"><a class="reference internal" href="../overview/goals.html">Architectural Goals</a></li> |
| 258 | </ul> |
| 259 | </li> |
| 260 | </ul> |
| 261 | <ul> |
| 262 | <li class="toctree-l1"><a class="reference internal" href="../tutorial/index.html">Tutorial</a><ul> |
| 263 | <li class="toctree-l2"><a class="reference internal" href="../tutorial/static_pages.html">Static pages</a></li> |
| 264 | <li class="toctree-l2"><a class="reference internal" href="../tutorial/news_section.html">News section</a></li> |
| 265 | <li class="toctree-l2"><a class="reference internal" href="../tutorial/create_news_items.html">Create news items</a></li> |
| 266 | <li class="toctree-l2"><a class="reference internal" href="../tutorial/conclusion.html">Conclusion</a></li> |
| 267 | </ul> |
| 268 | </li> |
| 269 | </ul> |
| 270 | <ul> |
| 271 | <li class="toctree-l1"><a class="reference internal" href="../contributing/index.html">Contributing to CodeIgniter</a><ul> |
| 272 | <li class="toctree-l2"><a class="reference internal" href="../documentation/index.html">Writing CodeIgniter Documentation</a></li> |
| 273 | <li class="toctree-l2"><a class="reference internal" href="../DCO.html">Developer’s Certificate of Origin 1.1</a></li> |
| 274 | </ul> |
| 275 | </li> |
| 276 | </ul> |
| 277 | <ul> |
| 278 | <li class="toctree-l1"><a class="reference internal" href="../general/index.html">General Topics</a><ul> |
| 279 | <li class="toctree-l2"><a class="reference internal" href="../general/urls.html">CodeIgniter URLs</a></li> |
| 280 | <li class="toctree-l2"><a class="reference internal" href="../general/controllers.html">Controllers</a></li> |
| 281 | <li class="toctree-l2"><a class="reference internal" href="../general/reserved_names.html">Reserved Names</a></li> |
| 282 | <li class="toctree-l2"><a class="reference internal" href="../general/views.html">Views</a></li> |
| 283 | <li class="toctree-l2"><a class="reference internal" href="../general/models.html">Models</a></li> |
| 284 | <li class="toctree-l2"><a class="reference internal" href="../general/helpers.html">Helpers</a></li> |
| 285 | <li class="toctree-l2"><a class="reference internal" href="../general/libraries.html">Using CodeIgniter Libraries</a></li> |
| 286 | <li class="toctree-l2"><a class="reference internal" href="../general/creating_libraries.html">Creating Libraries</a></li> |
| 287 | <li class="toctree-l2"><a class="reference internal" href="../general/drivers.html">Using CodeIgniter Drivers</a></li> |
| 288 | <li class="toctree-l2"><a class="reference internal" href="../general/creating_drivers.html">Creating Drivers</a></li> |
| 289 | <li class="toctree-l2"><a class="reference internal" href="../general/core_classes.html">Creating Core System Classes</a></li> |
| 290 | <li class="toctree-l2"><a class="reference internal" href="../general/ancillary_classes.html">Creating Ancillary Classes</a></li> |
| 291 | <li class="toctree-l2"><a class="reference internal" href="../general/hooks.html">Hooks - Extending the Framework Core</a></li> |
| 292 | <li class="toctree-l2"><a class="reference internal" href="../general/autoloader.html">Auto-loading Resources</a></li> |
| 293 | <li class="toctree-l2"><a class="reference internal" href="../general/common_functions.html">Common Functions</a></li> |
| 294 | <li class="toctree-l2"><a class="reference internal" href="../general/compatibility_functions.html">Compatibility Functions</a></li> |
| 295 | <li class="toctree-l2"><a class="reference internal" href="../general/routing.html">URI Routing</a></li> |
| 296 | <li class="toctree-l2"><a class="reference internal" href="../general/errors.html">Error Handling</a></li> |
| 297 | <li class="toctree-l2"><a class="reference internal" href="../general/caching.html">Caching</a></li> |
| 298 | <li class="toctree-l2"><a class="reference internal" href="../general/profiling.html">Profiling Your Application</a></li> |
| 299 | <li class="toctree-l2"><a class="reference internal" href="../general/cli.html">Running via the CLI</a></li> |
| 300 | <li class="toctree-l2"><a class="reference internal" href="../general/managing_apps.html">Managing your Applications</a></li> |
| 301 | <li class="toctree-l2"><a class="reference internal" href="../general/environments.html">Handling Multiple Environments</a></li> |
| 302 | <li class="toctree-l2"><a class="reference internal" href="../general/alternative_php.html">Alternate PHP Syntax for View Files</a></li> |
| 303 | <li class="toctree-l2"><a class="reference internal" href="../general/security.html">Security</a></li> |
| 304 | <li class="toctree-l2"><a class="reference internal" href="../general/styleguide.html">PHP Style Guide</a></li> |
| 305 | </ul> |
| 306 | </li> |
| 307 | </ul> |
| 308 | <ul class="current"> |
| 309 | <li class="toctree-l1 current"><a class="reference internal" href="index.html">Libraries</a><ul class="current"> |
| 310 | <li class="toctree-l2"><a class="reference internal" href="benchmark.html">Benchmarking Class</a></li> |
| 311 | <li class="toctree-l2"><a class="reference internal" href="caching.html">Caching Driver</a></li> |
| 312 | <li class="toctree-l2"><a class="reference internal" href="calendar.html">Calendaring Class</a></li> |
| 313 | <li class="toctree-l2"><a class="reference internal" href="cart.html">Shopping Cart Class</a></li> |
| 314 | <li class="toctree-l2"><a class="reference internal" href="config.html">Config Class</a></li> |
| 315 | <li class="toctree-l2"><a class="reference internal" href="email.html">Email Class</a></li> |
| 316 | <li class="toctree-l2"><a class="reference internal" href="encrypt.html">Encrypt Class</a></li> |
| 317 | <li class="toctree-l2 current"><a class="current reference internal" href="#">Encryption Library</a></li> |
| 318 | <li class="toctree-l2"><a class="reference internal" href="file_uploading.html">File Uploading Class</a></li> |
| 319 | <li class="toctree-l2"><a class="reference internal" href="form_validation.html">Form Validation</a></li> |
| 320 | <li class="toctree-l2"><a class="reference internal" href="ftp.html">FTP Class</a></li> |
| 321 | <li class="toctree-l2"><a class="reference internal" href="image_lib.html">Image Manipulation Class</a></li> |
| 322 | <li class="toctree-l2"><a class="reference internal" href="input.html">Input Class</a></li> |
| 323 | <li class="toctree-l2"><a class="reference internal" href="javascript.html">Javascript Class</a></li> |
| 324 | <li class="toctree-l2"><a class="reference internal" href="language.html">Language Class</a></li> |
| 325 | <li class="toctree-l2"><a class="reference internal" href="loader.html">Loader Class</a></li> |
| 326 | <li class="toctree-l2"><a class="reference internal" href="migration.html">Migrations Class</a></li> |
| 327 | <li class="toctree-l2"><a class="reference internal" href="output.html">Output Class</a></li> |
| 328 | <li class="toctree-l2"><a class="reference internal" href="pagination.html">Pagination Class</a></li> |
| 329 | <li class="toctree-l2"><a class="reference internal" href="parser.html">Template Parser Class</a></li> |
| 330 | <li class="toctree-l2"><a class="reference internal" href="security.html">Security Class</a></li> |
| 331 | <li class="toctree-l2"><a class="reference internal" href="sessions.html">Session Library</a></li> |
| 332 | <li class="toctree-l2"><a class="reference internal" href="table.html">HTML Table Class</a></li> |
| 333 | <li class="toctree-l2"><a class="reference internal" href="trackback.html">Trackback Class</a></li> |
| 334 | <li class="toctree-l2"><a class="reference internal" href="typography.html">Typography Class</a></li> |
| 335 | <li class="toctree-l2"><a class="reference internal" href="unit_testing.html">Unit Testing Class</a></li> |
| 336 | <li class="toctree-l2"><a class="reference internal" href="uri.html">URI Class</a></li> |
| 337 | <li class="toctree-l2"><a class="reference internal" href="user_agent.html">User Agent Class</a></li> |
| 338 | <li class="toctree-l2"><a class="reference internal" href="xmlrpc.html">XML-RPC and XML-RPC Server Classes</a></li> |
| 339 | <li class="toctree-l2"><a class="reference internal" href="zip.html">Zip Encoding Class</a></li> |
| 340 | </ul> |
| 341 | </li> |
| 342 | </ul> |
| 343 | <ul> |
| 344 | <li class="toctree-l1"><a class="reference internal" href="../database/index.html">Database Reference</a><ul> |
| 345 | <li class="toctree-l2"><a class="reference internal" href="../database/examples.html">Quick Start: Usage Examples</a></li> |
| 346 | <li class="toctree-l2"><a class="reference internal" href="../database/configuration.html">Database Configuration</a></li> |
| 347 | <li class="toctree-l2"><a class="reference internal" href="../database/connecting.html">Connecting to a Database</a></li> |
| 348 | <li class="toctree-l2"><a class="reference internal" href="../database/queries.html">Running Queries</a></li> |
| 349 | <li class="toctree-l2"><a class="reference internal" href="../database/results.html">Generating Query Results</a></li> |
| 350 | <li class="toctree-l2"><a class="reference internal" href="../database/helpers.html">Query Helper Functions</a></li> |
| 351 | <li class="toctree-l2"><a class="reference internal" href="../database/query_builder.html">Query Builder Class</a></li> |
| 352 | <li class="toctree-l2"><a class="reference internal" href="../database/transactions.html">Transactions</a></li> |
| 353 | <li class="toctree-l2"><a class="reference internal" href="../database/metadata.html">Getting MetaData</a></li> |
| 354 | <li class="toctree-l2"><a class="reference internal" href="../database/call_function.html">Custom Function Calls</a></li> |
| 355 | <li class="toctree-l2"><a class="reference internal" href="../database/caching.html">Query Caching</a></li> |
| 356 | <li class="toctree-l2"><a class="reference internal" href="../database/forge.html">Database Manipulation with Database Forge</a></li> |
| 357 | <li class="toctree-l2"><a class="reference internal" href="../database/utilities.html">Database Utilities Class</a></li> |
| 358 | <li class="toctree-l2"><a class="reference internal" href="../database/db_driver_reference.html">Database Driver Reference</a></li> |
| 359 | </ul> |
| 360 | </li> |
| 361 | </ul> |
| 362 | <ul> |
| 363 | <li class="toctree-l1"><a class="reference internal" href="../helpers/index.html">Helpers</a><ul> |
| 364 | <li class="toctree-l2"><a class="reference internal" href="../helpers/array_helper.html">Array Helper</a></li> |
| 365 | <li class="toctree-l2"><a class="reference internal" href="../helpers/captcha_helper.html">CAPTCHA Helper</a></li> |
| 366 | <li class="toctree-l2"><a class="reference internal" href="../helpers/cookie_helper.html">Cookie Helper</a></li> |
| 367 | <li class="toctree-l2"><a class="reference internal" href="../helpers/date_helper.html">Date Helper</a></li> |
| 368 | <li class="toctree-l2"><a class="reference internal" href="../helpers/directory_helper.html">Directory Helper</a></li> |
| 369 | <li class="toctree-l2"><a class="reference internal" href="../helpers/download_helper.html">Download Helper</a></li> |
| 370 | <li class="toctree-l2"><a class="reference internal" href="../helpers/email_helper.html">Email Helper</a></li> |
| 371 | <li class="toctree-l2"><a class="reference internal" href="../helpers/file_helper.html">File Helper</a></li> |
| 372 | <li class="toctree-l2"><a class="reference internal" href="../helpers/form_helper.html">Form Helper</a></li> |
| 373 | <li class="toctree-l2"><a class="reference internal" href="../helpers/html_helper.html">HTML Helper</a></li> |
| 374 | <li class="toctree-l2"><a class="reference internal" href="../helpers/inflector_helper.html">Inflector Helper</a></li> |
| 375 | <li class="toctree-l2"><a class="reference internal" href="../helpers/language_helper.html">Language Helper</a></li> |
| 376 | <li class="toctree-l2"><a class="reference internal" href="../helpers/number_helper.html">Number Helper</a></li> |
| 377 | <li class="toctree-l2"><a class="reference internal" href="../helpers/path_helper.html">Path Helper</a></li> |
| 378 | <li class="toctree-l2"><a class="reference internal" href="../helpers/security_helper.html">Security Helper</a></li> |
| 379 | <li class="toctree-l2"><a class="reference internal" href="../helpers/smiley_helper.html">Smiley Helper</a></li> |
| 380 | <li class="toctree-l2"><a class="reference internal" href="../helpers/string_helper.html">String Helper</a></li> |
| 381 | <li class="toctree-l2"><a class="reference internal" href="../helpers/text_helper.html">Text Helper</a></li> |
| 382 | <li class="toctree-l2"><a class="reference internal" href="../helpers/typography_helper.html">Typography Helper</a></li> |
| 383 | <li class="toctree-l2"><a class="reference internal" href="../helpers/url_helper.html">URL Helper</a></li> |
| 384 | <li class="toctree-l2"><a class="reference internal" href="../helpers/xml_helper.html">XML Helper</a></li> |
| 385 | </ul> |
| 386 | </li> |
| 387 | </ul> |
| 388 | |
| 389 | |
| 390 | |
| 391 | </div> |
| 392 | |
| 393 | </nav> |
| 394 | |
| 395 | <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"> |
| 396 | |
| 397 | |
| 398 | <nav class="wy-nav-top" role="navigation" aria-label="top navigation"> |
| 399 | <i data-toggle="wy-nav-top" class="fa fa-bars"></i> |
| 400 | <a href="../index.html">CodeIgniter</a> |
| 401 | </nav> |
| 402 | |
| 403 | |
| 404 | |
| 405 | <div class="wy-nav-content"> |
| 406 | <div class="rst-content"> |
| 407 | <div role="navigation" aria-label="breadcrumbs navigation"> |
| 408 | <ul class="wy-breadcrumbs"> |
| 409 | <li><a href="../index.html">Docs</a> »</li> |
| 410 | |
| 411 | <li><a href="index.html">Libraries</a> »</li> |
| 412 | |
| 413 | <li>Encryption Library</li> |
| 414 | <li class="wy-breadcrumbs-aside"> |
| 415 | |
| 416 | </li> |
| 417 | <div style="float:right;margin-left:5px;" id="closeMe"> |
| 418 | <img title="Classic Layout" alt="classic layout" src="data:image/gif;base64,R0lGODlhFAAUAJEAAAAAADMzM////wAAACH5BAUUAAIALAAAAAAUABQAAAImlI+py+0PU5gRBRDM3DxbWoXis42X13USOLauUIqnlsaH/eY6UwAAOw==" /> |
| 419 | </div> |
| 420 | </ul> |
| 421 | <hr/> |
| 422 | </div> |
| 423 | <div role="main" class="document"> |
| 424 | |
| 425 | <div class="section" id="encryption-library"> |
| 426 | <h1>Encryption Library<a class="headerlink" href="#encryption-library" title="Permalink to this headline">¶</a></h1> |
| 427 | <div class="admonition important"> |
| 428 | <p class="first admonition-title">Important</p> |
| 429 | <p class="last">DO NOT use this or any other <em>encryption</em> library for |
| 430 | user password storage! Passwords must be <em>hashed</em> instead, and you |
| 431 | should do that via PHP’s own <a class="reference external" href="http://php.net/password">Password Hashing extension</a>.</p> |
| 432 | </div> |
| 433 | <p>The Encryption Library provides two-way data encryption. To do so in |
| 434 | a cryptographically secure way, it utilizes PHP extensions that are |
| 435 | unfortunately not always available on all systems. |
| 436 | You must meet one of the following dependencies in order to use this |
| 437 | library:</p> |
| 438 | <ul class="simple"> |
| 439 | <li><a class="reference external" href="http://php.net/openssl">OpenSSL</a></li> |
| 440 | <li><a class="reference external" href="http://php.net/mcrypt">MCrypt</a> (and <cite>MCRYPT_DEV_URANDOM</cite> availability)</li> |
| 441 | </ul> |
| 442 | <p>If neither of the above dependencies is met, we simply cannot offer |
| 443 | you a good enough implementation to meet the high standards required |
| 444 | for proper cryptography.</p> |
| 445 | <div class="contents local topic" id="contents"> |
| 446 | <ul class="simple"> |
| 447 | <li><a class="reference internal" href="#using-the-encryption-library" id="id2">Using the Encryption Library</a><ul> |
| 448 | <li><a class="reference internal" href="#initializing-the-class" id="id3">Initializing the Class</a></li> |
| 449 | <li><a class="reference internal" href="#default-behavior" id="id4">Default behavior</a></li> |
| 450 | <li><a class="reference internal" href="#setting-your-encryption-key" id="id5">Setting your encryption_key</a></li> |
| 451 | <li><a class="reference internal" href="#supported-encryption-ciphers-and-modes" id="id6">Supported encryption ciphers and modes</a><ul> |
| 452 | <li><a class="reference internal" href="#portable-ciphers" id="id7">Portable ciphers</a></li> |
| 453 | <li><a class="reference internal" href="#driver-specific-ciphers" id="id8">Driver-specific ciphers</a></li> |
| 454 | <li><a class="reference internal" href="#encryption-modes" id="id9">Encryption modes</a></li> |
| 455 | </ul> |
| 456 | </li> |
| 457 | <li><a class="reference internal" href="#message-length" id="id10">Message Length</a></li> |
| 458 | <li><a class="reference internal" href="#configuring-the-library" id="id11">Configuring the library</a></li> |
| 459 | <li><a class="reference internal" href="#encrypting-and-decrypting-data" id="id12">Encrypting and decrypting data</a><ul> |
| 460 | <li><a class="reference internal" href="#how-it-works" id="id13">How it works</a></li> |
| 461 | <li><a class="reference internal" href="#using-custom-parameters" id="id14">Using custom parameters</a></li> |
| 462 | <li><a class="reference internal" href="#supported-hmac-authentication-algorithms" id="id15">Supported HMAC authentication algorithms</a></li> |
| 463 | </ul> |
| 464 | </li> |
| 465 | </ul> |
| 466 | </li> |
| 467 | <li><a class="reference internal" href="#class-reference" id="id16">Class Reference</a></li> |
| 468 | </ul> |
| 469 | </div> |
| 470 | <div class="custom-index container"></div><div class="section" id="using-the-encryption-library"> |
| 471 | <h2><a class="toc-backref" href="#id2">Using the Encryption Library</a><a class="headerlink" href="#using-the-encryption-library" title="Permalink to this headline">¶</a></h2> |
| 472 | <div class="section" id="initializing-the-class"> |
| 473 | <h3><a class="toc-backref" href="#id3">Initializing the Class</a><a class="headerlink" href="#initializing-the-class" title="Permalink to this headline">¶</a></h3> |
| 474 | <p>Like most other classes in CodeIgniter, the Encryption library is |
| 475 | initialized in your controller using the <code class="docutils literal"><span class="pre">$this->load->library()</span></code> |
| 476 | method:</p> |
| 477 | <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$this</span><span class="o">-></span><span class="na">load</span><span class="o">-></span><span class="na">library</span><span class="p">(</span><span class="s1">'encryption'</span><span class="p">);</span> |
| 478 | </pre></div> |
| 479 | </div> |
| 480 | <p>Once loaded, the Encryption library object will be available using:</p> |
| 481 | <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$this</span><span class="o">-></span><span class="na">encryption</span> |
| 482 | </pre></div> |
| 483 | </div> |
| 484 | </div> |
| 485 | <div class="section" id="default-behavior"> |
| 486 | <h3><a class="toc-backref" href="#id4">Default behavior</a><a class="headerlink" href="#default-behavior" title="Permalink to this headline">¶</a></h3> |
| 487 | <p>By default, the Encryption Library will use the AES-128 cipher in CBC |
| 488 | mode, using your configured <em>encryption_key</em> and SHA512 HMAC authentication.</p> |
| 489 | <div class="admonition note"> |
| 490 | <p class="first admonition-title">Note</p> |
| 491 | <p class="last">AES-128 is chosen both because it is proven to be strong and |
| 492 | because of its wide availability across different cryptographic |
| 493 | software and programming languages’ APIs.</p> |
| 494 | </div> |
| 495 | <p>However, the <em>encryption_key</em> is not used as is.</p> |
| 496 | <p>If you are somewhat familiar with cryptography, you should already know |
| 497 | that a HMAC also requires a secret key and using the same key for both |
| 498 | encryption and authentication is a bad practice.</p> |
| 499 | <p>Because of that, two separate keys are derived from your already configured |
| 500 | <em>encryption_key</em>: one for encryption and one for authentication. This is |
| 501 | done via a technique called <a class="reference external" href="http://en.wikipedia.org/wiki/HKDF">HMAC-based Key Derivation Function</a> (HKDF).</p> |
| 502 | </div> |
| 503 | <div class="section" id="setting-your-encryption-key"> |
| 504 | <h3><a class="toc-backref" href="#id5">Setting your encryption_key</a><a class="headerlink" href="#setting-your-encryption-key" title="Permalink to this headline">¶</a></h3> |
| 505 | <p>An <em>encryption key</em> is a piece of information that controls the |
| 506 | cryptographic process and permits a plain-text string to be encrypted, |
| 507 | and afterwards - decrypted. It is the secret “ingredient” in the whole |
| 508 | process that allows you to be the only one who is able to decrypt data |
| 509 | that you’ve decided to hide from the eyes of the public. |
| 510 | After one key is used to encrypt data, that same key provides the <strong>only</strong> |
| 511 | means to decrypt it, so not only must you chose one carefully, but you |
| 512 | must not lose it or you will also lose access to the data.</p> |
| 513 | <p>It must be noted that to ensure maximum security, such key <em>should</em> not |
| 514 | only be as strong as possible, but also often changed. Such behavior |
| 515 | however is rarely practical or possible to implement, and that is why |
| 516 | CodeIgniter gives you the ability to configure a single key that is to be |
| 517 | used (almost) every time.</p> |
| 518 | <p>It goes without saying that you should guard your key carefully. Should |
| 519 | someone gain access to your key, the data will be easily decrypted. If |
| 520 | your server is not totally under your control it’s impossible to ensure |
| 521 | key security so you may want to think carefully before using it for |
| 522 | anything that requires high security, like storing credit card numbers.</p> |
| 523 | <p>Your encryption key <strong>must</strong> be as long as the encyption algorithm in use |
| 524 | allows. For AES-128, that’s 128 bits or 16 bytes (charcters) long. |
| 525 | You will find a table below that shows the supported key lengths of |
| 526 | different ciphers.</p> |
| 527 | <p>The key should be as random as possible and it <strong>must not</strong> be a regular |
| 528 | text string, nor the output of a hashing function, etc. In order to create |
| 529 | a proper key, you must use the Encryption library’s <code class="docutils literal"><span class="pre">create_key()</span></code> method</p> |
| 530 | <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="c1">// $key will be assigned a 16-byte (128-bit) random key</span> |
| 531 | <span class="nv">$key</span> <span class="o">=</span> <span class="nv">$this</span><span class="o">-></span><span class="na">encryption</span><span class="o">-></span><span class="na">create_key</span><span class="p">(</span><span class="mi">16</span><span class="p">);</span> |
| 532 | </pre></div> |
| 533 | </div> |
| 534 | <p>The key can be either stored in your <em>application/config/config.php</em>, or |
| 535 | you can design your own storage mechanism and pass the key dynamically |
| 536 | when encrypting/decrypting.</p> |
| 537 | <p>To save your key to your <em>application/config/config.php</em>, open the file |
| 538 | and set:</p> |
| 539 | <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$config</span><span class="p">[</span><span class="s1">'encryption_key'</span><span class="p">]</span> <span class="o">=</span> <span class="s1">'YOUR KEY'</span><span class="p">;</span> |
| 540 | </pre></div> |
| 541 | </div> |
| 542 | <p>You’ll notice that the <code class="docutils literal"><span class="pre">create_key()</span></code> method outputs binary data, which |
| 543 | is hard to deal with (i.e. a copy-paste may damage it), so you may use |
| 544 | <code class="docutils literal"><span class="pre">bin2hex()</span></code>, <code class="docutils literal"><span class="pre">hex2bin()</span></code> or Base64-encoding to work with the key in |
| 545 | a more friendly manner. For example:</p> |
| 546 | <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="c1">// Get a hex-encoded representation of the key:</span> |
| 547 | <span class="nv">$key</span> <span class="o">=</span> <span class="nb">bin2hex</span><span class="p">(</span><span class="nv">$this</span><span class="o">-></span><span class="na">encryption</span><span class="o">-></span><span class="na">create_key</span><span class="p">(</span><span class="mi">16</span><span class="p">));</span> |
| 548 | |
| 549 | <span class="c1">// Put the same value in your config with hex2bin(),</span> |
| 550 | <span class="c1">// so that it is still passed as binary to the library:</span> |
| 551 | <span class="nv">$config</span><span class="p">[</span><span class="s1">'encryption_key'</span><span class="p">]</span> <span class="o">=</span> <span class="nb">hex2bin</span><span class="p">(</span><span class="o"><</span><span class="nx">your</span> <span class="nx">hex</span><span class="o">-</span><span class="nx">encoded</span> <span class="nb">key</span><span class="o">></span><span class="p">);</span> |
| 552 | </pre></div> |
| 553 | </div> |
| 554 | </div> |
| 555 | <div class="section" id="supported-encryption-ciphers-and-modes"> |
| 556 | <span id="ciphers-and-modes"></span><h3><a class="toc-backref" href="#id6">Supported encryption ciphers and modes</a><a class="headerlink" href="#supported-encryption-ciphers-and-modes" title="Permalink to this headline">¶</a></h3> |
| 557 | <div class="admonition note"> |
| 558 | <p class="first admonition-title">Note</p> |
| 559 | <p class="last">The terms ‘cipher’ and ‘encryption algorithm’ are interchangeable.</p> |
| 560 | </div> |
| 561 | <div class="section" id="portable-ciphers"> |
| 562 | <h4><a class="toc-backref" href="#id7">Portable ciphers</a><a class="headerlink" href="#portable-ciphers" title="Permalink to this headline">¶</a></h4> |
| 563 | <p>Because MCrypt and OpenSSL (also called drivers throughout this document) |
| 564 | each support different sets of encryption algorithms and often implement |
| 565 | them in different ways, our Encryption library is designed to use them in |
| 566 | a portable fashion, or in other words - it enables you to use them |
| 567 | interchangeably, at least for the ciphers supported by both drivers.</p> |
| 568 | <p>It is also implemented in a way that aims to match the standard |
| 569 | implementations in other programming languages and libraries.</p> |
| 570 | <p>Here’s a list of the so called “portable” ciphers, where |
| 571 | “CodeIgniter name” is the string value that you’d have to pass to the |
| 572 | Encryption library to use that cipher:</p> |
| 573 | <table border="1" class="docutils"> |
| 574 | <colgroup> |
| 575 | <col width="24%" /> |
| 576 | <col width="18%" /> |
| 577 | <col width="28%" /> |
| 578 | <col width="31%" /> |
| 579 | </colgroup> |
| 580 | <thead valign="bottom"> |
| 581 | <tr class="row-odd"><th class="head">Cipher name</th> |
| 582 | <th class="head">CodeIgniter name</th> |
| 583 | <th class="head">Key lengths (bits / bytes)</th> |
| 584 | <th class="head">Supported modes</th> |
| 585 | </tr> |
| 586 | </thead> |
| 587 | <tbody valign="top"> |
| 588 | <tr class="row-even"><td>AES-128 / Rijndael-128</td> |
| 589 | <td>aes-128</td> |
| 590 | <td>128 / 16</td> |
| 591 | <td>CBC, CTR, CFB, CFB8, OFB, ECB</td> |
| 592 | </tr> |
| 593 | <tr class="row-odd"><td>AES-192</td> |
| 594 | <td>aes-192</td> |
| 595 | <td>192 / 24</td> |
| 596 | <td>CBC, CTR, CFB, CFB8, OFB, ECB</td> |
| 597 | </tr> |
| 598 | <tr class="row-even"><td>AES-256</td> |
| 599 | <td>aes-256</td> |
| 600 | <td>256 / 32</td> |
| 601 | <td>CBC, CTR, CFB, CFB8, OFB, ECB</td> |
| 602 | </tr> |
| 603 | <tr class="row-odd"><td>DES</td> |
| 604 | <td>des</td> |
| 605 | <td>56 / 7</td> |
| 606 | <td>CBC, CFB, CFB8, OFB, ECB</td> |
| 607 | </tr> |
| 608 | <tr class="row-even"><td>TripleDES</td> |
| 609 | <td>tripledes</td> |
| 610 | <td>56 / 7, 112 / 14, 168 / 21</td> |
| 611 | <td>CBC, CFB, CFB8, OFB</td> |
| 612 | </tr> |
| 613 | <tr class="row-odd"><td>Blowfish</td> |
| 614 | <td>blowfish</td> |
| 615 | <td>128-448 / 16-56</td> |
| 616 | <td>CBC, CFB, OFB, ECB</td> |
| 617 | </tr> |
| 618 | <tr class="row-even"><td>CAST5 / CAST-128</td> |
| 619 | <td>cast5</td> |
| 620 | <td>88-128 / 11-16</td> |
| 621 | <td>CBC, CFB, OFB, ECB</td> |
| 622 | </tr> |
| 623 | <tr class="row-odd"><td>RC4 / ARCFour</td> |
| 624 | <td>rc4</td> |
| 625 | <td>40-2048 / 5-256</td> |
| 626 | <td>Stream</td> |
| 627 | </tr> |
| 628 | </tbody> |
| 629 | </table> |
| 630 | <div class="admonition important"> |
| 631 | <p class="first admonition-title">Important</p> |
| 632 | <p class="last">Because of how MCrypt works, if you fail to provide a key |
| 633 | with the appropriate length, you might end up using a different |
| 634 | algorithm than the one configured, so be really careful with that!</p> |
| 635 | </div> |
| 636 | <div class="admonition note"> |
| 637 | <p class="first admonition-title">Note</p> |
| 638 | <p class="last">In case it isn’t clear from the above table, Blowfish, CAST5 |
| 639 | and RC4 support variable length keys. That is, any number in the |
| 640 | shown ranges is valid, although in bit terms that only happens |
| 641 | in 8-bit increments.</p> |
| 642 | </div> |
| 643 | <div class="admonition note"> |
| 644 | <p class="first admonition-title">Note</p> |
| 645 | <p class="last">Even though CAST5 supports key lengths lower than 128 bits |
| 646 | (16 bytes), in fact they will just be zero-padded to the |
| 647 | maximum length, as specified in <a class="reference external" href="http://tools.ietf.org/rfc/rfc2144.txt">RFC 2144</a>.</p> |
| 648 | </div> |
| 649 | <div class="admonition note"> |
| 650 | <p class="first admonition-title">Note</p> |
| 651 | <p class="last">Blowfish supports key lengths as small as 32 bits (4 bytes), but |
| 652 | our tests have shown that only lengths of 128 bits (16 bytes) or |
| 653 | higher are properly supported by both MCrypt and OpenSSL. It is |
| 654 | also a bad practice to use such low-length keys anyway.</p> |
| 655 | </div> |
| 656 | </div> |
| 657 | <div class="section" id="driver-specific-ciphers"> |
| 658 | <h4><a class="toc-backref" href="#id8">Driver-specific ciphers</a><a class="headerlink" href="#driver-specific-ciphers" title="Permalink to this headline">¶</a></h4> |
| 659 | <p>As noted above, MCrypt and OpenSSL support different sets of encryption |
| 660 | ciphers. For portability reasons and because we haven’t tested them |
| 661 | properly, we do not advise you to use the ones that are driver-specific, |
| 662 | but regardless, here’s a list of most of them:</p> |
| 663 | <table border="1" class="docutils"> |
| 664 | <colgroup> |
| 665 | <col width="15%" /> |
| 666 | <col width="10%" /> |
| 667 | <col width="32%" /> |
| 668 | <col width="44%" /> |
| 669 | </colgroup> |
| 670 | <thead valign="bottom"> |
| 671 | <tr class="row-odd"><th class="head">Cipher name</th> |
| 672 | <th class="head">Driver</th> |
| 673 | <th class="head">Key lengths (bits / bytes)</th> |
| 674 | <th class="head">Supported modes</th> |
| 675 | </tr> |
| 676 | </thead> |
| 677 | <tbody valign="top"> |
| 678 | <tr class="row-even"><td>AES-128</td> |
| 679 | <td>OpenSSL</td> |
| 680 | <td>128 / 16</td> |
| 681 | <td>CBC, CTR, CFB, CFB8, OFB, ECB, XTS</td> |
| 682 | </tr> |
| 683 | <tr class="row-odd"><td>AES-192</td> |
| 684 | <td>OpenSSL</td> |
| 685 | <td>192 / 24</td> |
| 686 | <td>CBC, CTR, CFB, CFB8, OFB, ECB, XTS</td> |
| 687 | </tr> |
| 688 | <tr class="row-even"><td>AES-256</td> |
| 689 | <td>OpenSSL</td> |
| 690 | <td>256 / 32</td> |
| 691 | <td>CBC, CTR, CFB, CFB8, OFB, ECB, XTS</td> |
| 692 | </tr> |
| 693 | <tr class="row-odd"><td>Rijndael-128</td> |
| 694 | <td>MCrypt</td> |
| 695 | <td>128 / 16, 192 / 24, 256 / 32</td> |
| 696 | <td>CBC, CTR, CFB, CFB8, OFB, OFB8, ECB</td> |
| 697 | </tr> |
| 698 | <tr class="row-even"><td>Rijndael-192</td> |
| 699 | <td>MCrypt</td> |
| 700 | <td>128 / 16, 192 / 24, 256 / 32</td> |
| 701 | <td>CBC, CTR, CFB, CFB8, OFB, OFB8, ECB</td> |
| 702 | </tr> |
| 703 | <tr class="row-odd"><td>Rijndael-256</td> |
| 704 | <td>MCrypt</td> |
| 705 | <td>128 / 16, 192 / 24, 256 / 32</td> |
| 706 | <td>CBC, CTR, CFB, CFB8, OFB, OFB8, ECB</td> |
| 707 | </tr> |
| 708 | <tr class="row-even"><td>GOST</td> |
| 709 | <td>MCrypt</td> |
| 710 | <td>256 / 32</td> |
| 711 | <td>CBC, CTR, CFB, CFB8, OFB, OFB8, ECB</td> |
| 712 | </tr> |
| 713 | <tr class="row-odd"><td>Twofish</td> |
| 714 | <td>MCrypt</td> |
| 715 | <td>128 / 16, 192 / 24, 256 / 32</td> |
| 716 | <td>CBC, CTR, CFB, CFB8, OFB, OFB8, ECB</td> |
| 717 | </tr> |
| 718 | <tr class="row-even"><td>CAST-128</td> |
| 719 | <td>MCrypt</td> |
| 720 | <td>40-128 / 5-16</td> |
| 721 | <td>CBC, CTR, CFB, CFB8, OFB, OFB8, ECB</td> |
| 722 | </tr> |
| 723 | <tr class="row-odd"><td>CAST-256</td> |
| 724 | <td>MCrypt</td> |
| 725 | <td>128 / 16, 192 / 24, 256 / 32</td> |
| 726 | <td>CBC, CTR, CFB, CFB8, OFB, OFB8, ECB</td> |
| 727 | </tr> |
| 728 | <tr class="row-even"><td>Loki97</td> |
| 729 | <td>MCrypt</td> |
| 730 | <td>128 / 16, 192 / 24, 256 / 32</td> |
| 731 | <td>CBC, CTR, CFB, CFB8, OFB, OFB8, ECB</td> |
| 732 | </tr> |
| 733 | <tr class="row-odd"><td>SaferPlus</td> |
| 734 | <td>MCrypt</td> |
| 735 | <td>128 / 16, 192 / 24, 256 / 32</td> |
| 736 | <td>CBC, CTR, CFB, CFB8, OFB, OFB8, ECB</td> |
| 737 | </tr> |
| 738 | <tr class="row-even"><td>Serpent</td> |
| 739 | <td>MCrypt</td> |
| 740 | <td>128 / 16, 192 / 24, 256 / 32</td> |
| 741 | <td>CBC, CTR, CFB, CFB8, OFB, OFB8, ECB</td> |
| 742 | </tr> |
| 743 | <tr class="row-odd"><td>XTEA</td> |
| 744 | <td>MCrypt</td> |
| 745 | <td>128 / 16</td> |
| 746 | <td>CBC, CTR, CFB, CFB8, OFB, OFB8, ECB</td> |
| 747 | </tr> |
| 748 | <tr class="row-even"><td>RC2</td> |
| 749 | <td>MCrypt</td> |
| 750 | <td>8-1024 / 1-128</td> |
| 751 | <td>CBC, CTR, CFB, CFB8, OFB, OFB8, ECB</td> |
| 752 | </tr> |
| 753 | <tr class="row-odd"><td>RC2</td> |
| 754 | <td>OpenSSL</td> |
| 755 | <td>8-1024 / 1-128</td> |
| 756 | <td>CBC, CFB, OFB, ECB</td> |
| 757 | </tr> |
| 758 | <tr class="row-even"><td>Camellia-128</td> |
| 759 | <td>OpenSSL</td> |
| 760 | <td>128 / 16</td> |
| 761 | <td>CBC, CFB, CFB8, OFB, ECB</td> |
| 762 | </tr> |
| 763 | <tr class="row-odd"><td>Camellia-192</td> |
| 764 | <td>OpenSSL</td> |
| 765 | <td>192 / 24</td> |
| 766 | <td>CBC, CFB, CFB8, OFB, ECB</td> |
| 767 | </tr> |
| 768 | <tr class="row-even"><td>Camellia-256</td> |
| 769 | <td>OpenSSL</td> |
| 770 | <td>256 / 32</td> |
| 771 | <td>CBC, CFB, CFB8, OFB, ECB</td> |
| 772 | </tr> |
| 773 | <tr class="row-odd"><td>Seed</td> |
| 774 | <td>OpenSSL</td> |
| 775 | <td>128 / 16</td> |
| 776 | <td>CBC, CFB, OFB, ECB</td> |
| 777 | </tr> |
| 778 | </tbody> |
| 779 | </table> |
| 780 | <div class="admonition note"> |
| 781 | <p class="first admonition-title">Note</p> |
| 782 | <p class="last">If you wish to use one of those ciphers, you’d have to pass |
| 783 | its name in lower-case to the Encryption library.</p> |
| 784 | </div> |
| 785 | <div class="admonition note"> |
| 786 | <p class="first admonition-title">Note</p> |
| 787 | <p class="last">You’ve probably noticed that all AES cipers (and Rijndael-128) |
| 788 | are also listed in the portable ciphers list. This is because |
| 789 | drivers support different modes for these ciphers. Also, it is |
| 790 | important to note that AES-128 and Rijndael-128 are actually |
| 791 | the same cipher, but <strong>only</strong> when used with a 128-bit key.</p> |
| 792 | </div> |
| 793 | <div class="admonition note"> |
| 794 | <p class="first admonition-title">Note</p> |
| 795 | <p class="last">CAST-128 / CAST-5 is also listed in both the portable and |
| 796 | driver-specific ciphers list. This is because OpenSSL’s |
| 797 | implementation doesn’t appear to be working correctly with |
| 798 | key sizes of 80 bits and lower.</p> |
| 799 | </div> |
| 800 | <div class="admonition note"> |
| 801 | <p class="first admonition-title">Note</p> |
| 802 | <p class="last">RC2 is listed as supported by both MCrypt and OpenSSL. |
| 803 | However, both drivers implement them differently and they |
| 804 | are not portable. It is probably worth noting that we only |
| 805 | found one obscure source confirming that it is MCrypt that |
| 806 | is not properly implementing it.</p> |
| 807 | </div> |
| 808 | </div> |
| 809 | <div class="section" id="encryption-modes"> |
| 810 | <span id="id1"></span><h4><a class="toc-backref" href="#id9">Encryption modes</a><a class="headerlink" href="#encryption-modes" title="Permalink to this headline">¶</a></h4> |
| 811 | <p>Different modes of encryption have different characteristics and serve |
| 812 | for different purposes. Some are stronger than others, some are faster |
| 813 | and some offer extra features. |
| 814 | We are not going in depth into that here, we’ll leave that to the |
| 815 | cryptography experts. The table below is to provide brief informational |
| 816 | reference to our more experienced users. If you are a beginner, just |
| 817 | stick to the CBC mode - it is widely accepted as strong and secure for |
| 818 | general purposes.</p> |
| 819 | <table border="1" class="docutils"> |
| 820 | <colgroup> |
| 821 | <col width="6%" /> |
| 822 | <col width="9%" /> |
| 823 | <col width="9%" /> |
| 824 | <col width="76%" /> |
| 825 | </colgroup> |
| 826 | <thead valign="bottom"> |
| 827 | <tr class="row-odd"><th class="head">Mode name</th> |
| 828 | <th class="head">CodeIgniter name</th> |
| 829 | <th class="head">Driver support</th> |
| 830 | <th class="head">Additional info</th> |
| 831 | </tr> |
| 832 | </thead> |
| 833 | <tbody valign="top"> |
| 834 | <tr class="row-even"><td>CBC</td> |
| 835 | <td>cbc</td> |
| 836 | <td>MCrypt, OpenSSL</td> |
| 837 | <td>A safe default choice</td> |
| 838 | </tr> |
| 839 | <tr class="row-odd"><td>CTR</td> |
| 840 | <td>ctr</td> |
| 841 | <td>MCrypt, OpenSSL</td> |
| 842 | <td>Considered as theoretically better than CBC, but not as widely available</td> |
| 843 | </tr> |
| 844 | <tr class="row-even"><td>CFB</td> |
| 845 | <td>cfb</td> |
| 846 | <td>MCrypt, OpenSSL</td> |
| 847 | <td>N/A</td> |
| 848 | </tr> |
| 849 | <tr class="row-odd"><td>CFB8</td> |
| 850 | <td>cfb8</td> |
| 851 | <td>MCrypt, OpenSSL</td> |
| 852 | <td>Same as CFB, but operates in 8-bit mode (not recommended).</td> |
| 853 | </tr> |
| 854 | <tr class="row-even"><td>OFB</td> |
| 855 | <td>ofb</td> |
| 856 | <td>MCrypt, OpenSSL</td> |
| 857 | <td>N/A</td> |
| 858 | </tr> |
| 859 | <tr class="row-odd"><td>OFB8</td> |
| 860 | <td>ofb8</td> |
| 861 | <td>MCrypt</td> |
| 862 | <td>Same as OFB, but operates in 8-bit mode (not recommended).</td> |
| 863 | </tr> |
| 864 | <tr class="row-even"><td>ECB</td> |
| 865 | <td>ecb</td> |
| 866 | <td>MCrypt, OpenSSL</td> |
| 867 | <td>Ignores IV (not recommended).</td> |
| 868 | </tr> |
| 869 | <tr class="row-odd"><td>XTS</td> |
| 870 | <td>xts</td> |
| 871 | <td>OpenSSL</td> |
| 872 | <td>Usually used for encrypting random access data such as RAM or hard-disk storage.</td> |
| 873 | </tr> |
| 874 | <tr class="row-even"><td>Stream</td> |
| 875 | <td>stream</td> |
| 876 | <td>MCrypt, OpenSSL</td> |
| 877 | <td>This is not actually a mode, it just says that a stream cipher is being used. Required because of the general cipher+mode initialization process.</td> |
| 878 | </tr> |
| 879 | </tbody> |
| 880 | </table> |
| 881 | </div> |
| 882 | </div> |
| 883 | <div class="section" id="message-length"> |
| 884 | <h3><a class="toc-backref" href="#id10">Message Length</a><a class="headerlink" href="#message-length" title="Permalink to this headline">¶</a></h3> |
| 885 | <p>It’s probably important for you to know that an encrypted string is usually |
| 886 | longer than the original, plain-text string (depending on the cipher).</p> |
| 887 | <p>This is influenced by the cipher algorithm itself, the IV prepended to the |
| 888 | cipher-text and the HMAC authentication message that is also prepended. |
| 889 | Furthermore, the encrypted message is also Base64-encoded so that it is safe |
| 890 | for storage and transmission, regardless of a possible character set in use.</p> |
| 891 | <p>Keep this information in mind when selecting your data storage mechanism. |
| 892 | Cookies, for example, can only hold 4K of information.</p> |
| 893 | </div> |
| 894 | <div class="section" id="configuring-the-library"> |
| 895 | <span id="configuration"></span><h3><a class="toc-backref" href="#id11">Configuring the library</a><a class="headerlink" href="#configuring-the-library" title="Permalink to this headline">¶</a></h3> |
| 896 | <p>For usability, performance, but also historical reasons tied to our old |
| 897 | <a class="reference internal" href="encrypt.html"><span class="doc">Encrypt Class</span></a>, the Encryption library is designed to |
| 898 | use repeatedly the same driver, encryption cipher, mode and key.</p> |
| 899 | <p>As noted in the “Default behavior” section above, this means using an |
| 900 | auto-detected driver (OpenSSL has a higher priority), the AES-128 ciper |
| 901 | in CBC mode, and your <code class="docutils literal"><span class="pre">$config['encryption_key']</span></code> value.</p> |
| 902 | <p>If you wish to change that however, you need to use the <code class="docutils literal"><span class="pre">initialize()</span></code> |
| 903 | method. It accepts an associative array of parameters, all of which are |
| 904 | optional:</p> |
| 905 | <table border="1" class="docutils"> |
| 906 | <colgroup> |
| 907 | <col width="15%" /> |
| 908 | <col width="85%" /> |
| 909 | </colgroup> |
| 910 | <thead valign="bottom"> |
| 911 | <tr class="row-odd"><th class="head">Option</th> |
| 912 | <th class="head">Possible values</th> |
| 913 | </tr> |
| 914 | </thead> |
| 915 | <tbody valign="top"> |
| 916 | <tr class="row-even"><td>driver</td> |
| 917 | <td>‘mcrypt’, ‘openssl’</td> |
| 918 | </tr> |
| 919 | <tr class="row-odd"><td>cipher</td> |
| 920 | <td>Cipher name (see <a class="reference internal" href="#ciphers-and-modes"><span class="std std-ref">Supported encryption ciphers and modes</span></a>)</td> |
| 921 | </tr> |
| 922 | <tr class="row-even"><td>mode</td> |
| 923 | <td>Encryption mode (see <a class="reference internal" href="#encryption-modes"><span class="std std-ref">Encryption modes</span></a>)</td> |
| 924 | </tr> |
| 925 | <tr class="row-odd"><td>key</td> |
| 926 | <td>Encryption key</td> |
| 927 | </tr> |
| 928 | </tbody> |
| 929 | </table> |
| 930 | <p>For example, if you were to change the encryption algorithm and |
| 931 | mode to AES-256 in CTR mode, this is what you should do:</p> |
| 932 | <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$this</span><span class="o">-></span><span class="na">encryption</span><span class="o">-></span><span class="na">initialize</span><span class="p">(</span> |
| 933 | <span class="k">array</span><span class="p">(</span> |
| 934 | <span class="s1">'cipher'</span> <span class="o">=></span> <span class="s1">'aes-256'</span><span class="p">,</span> |
| 935 | <span class="s1">'mode'</span> <span class="o">=></span> <span class="s1">'ctr'</span><span class="p">,</span> |
| 936 | <span class="s1">'key'</span> <span class="o">=></span> <span class="s1">'<a 32-character random string>'</span> |
| 937 | <span class="p">)</span> |
| 938 | <span class="p">);</span> |
| 939 | </pre></div> |
| 940 | </div> |
| 941 | <p>Note that we only mentioned that you want to change the ciper and mode, |
| 942 | but we also included a key in the example. As previously noted, it is |
| 943 | important that you choose a key with a proper size for the used algorithm.</p> |
| 944 | <p>There’s also the ability to change the driver, if for some reason you |
| 945 | have both, but want to use MCrypt instead of OpenSSL:</p> |
| 946 | <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="c1">// Switch to the MCrypt driver</span> |
| 947 | <span class="nv">$this</span><span class="o">-></span><span class="na">encryption</span><span class="o">-></span><span class="na">initialize</span><span class="p">(</span><span class="k">array</span><span class="p">(</span><span class="s1">'driver'</span> <span class="o">=></span> <span class="s1">'mcrypt'</span><span class="p">));</span> |
| 948 | |
| 949 | <span class="c1">// Switch back to the OpenSSL driver</span> |
| 950 | <span class="nv">$this</span><span class="o">-></span><span class="na">encryption</span><span class="o">-></span><span class="na">initialize</span><span class="p">(</span><span class="k">array</span><span class="p">(</span><span class="s1">'driver'</span> <span class="o">=></span> <span class="s1">'openssl'</span><span class="p">));</span> |
| 951 | </pre></div> |
| 952 | </div> |
| 953 | </div> |
| 954 | <div class="section" id="encrypting-and-decrypting-data"> |
| 955 | <h3><a class="toc-backref" href="#id12">Encrypting and decrypting data</a><a class="headerlink" href="#encrypting-and-decrypting-data" title="Permalink to this headline">¶</a></h3> |
| 956 | <p>Encrypting and decrypting data with the already configured library |
| 957 | settings is simple. As simple as just passing the string to the |
| 958 | <code class="docutils literal"><span class="pre">encrypt()</span></code> and/or <code class="docutils literal"><span class="pre">decrypt()</span></code> methods:</p> |
| 959 | <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$plain_text</span> <span class="o">=</span> <span class="s1">'This is a plain-text message!'</span><span class="p">;</span> |
| 960 | <span class="nv">$ciphertext</span> <span class="o">=</span> <span class="nv">$this</span><span class="o">-></span><span class="na">encryption</span><span class="o">-></span><span class="na">encrypt</span><span class="p">(</span><span class="nv">$plain_text</span><span class="p">);</span> |
| 961 | |
| 962 | <span class="c1">// Outputs: This is a plain-text message!</span> |
| 963 | <span class="k">echo</span> <span class="nv">$this</span><span class="o">-></span><span class="na">encryption</span><span class="o">-></span><span class="na">decrypt</span><span class="p">(</span><span class="nv">$ciphertext</span><span class="p">);</span> |
| 964 | </pre></div> |
| 965 | </div> |
| 966 | <p>And that’s it! The Encryption library will do everything necessary |
| 967 | for the whole process to be cryptographically secure out-of-the-box. |
| 968 | You don’t need to worry about it.</p> |
| 969 | <div class="admonition important"> |
| 970 | <p class="first admonition-title">Important</p> |
| 971 | <p class="last">Both methods will return FALSE in case of an error. |
| 972 | While for <code class="docutils literal"><span class="pre">encrypt()</span></code> this can only mean incorrect |
| 973 | configuration, you should always check the return value |
| 974 | of <code class="docutils literal"><span class="pre">decrypt()</span></code> in production code.</p> |
| 975 | </div> |
| 976 | <div class="section" id="how-it-works"> |
| 977 | <h4><a class="toc-backref" href="#id13">How it works</a><a class="headerlink" href="#how-it-works" title="Permalink to this headline">¶</a></h4> |
| 978 | <p>If you must know how the process works, here’s what happens under |
| 979 | the hood:</p> |
| 980 | <ul class="simple"> |
| 981 | <li><code class="docutils literal"><span class="pre">$this->encryption->encrypt($plain_text)</span></code><ol class="arabic"> |
| 982 | <li>Derive an encryption key and a HMAC key from your configured |
| 983 | <em>encryption_key</em> via HKDF, using the SHA-512 digest algorithm.</li> |
| 984 | <li>Generate a random initialization vector (IV).</li> |
| 985 | <li>Encrypt the data via AES-128 in CBC mode (or another previously |
| 986 | configured cipher and mode), using the above-mentioned derived |
| 987 | encryption key and IV.</li> |
| 988 | <li>Prepend said IV to the resulting cipher-text.</li> |
| 989 | <li>Base64-encode the resulting string, so that it can be safely |
| 990 | stored or transferred without worrying about character sets.</li> |
| 991 | <li>Create a SHA-512 HMAC authentication message using the derived |
| 992 | HMAC key to ensure data integrity and prepend it to the Base64 |
| 993 | string.</li> |
| 994 | </ol> |
| 995 | </li> |
| 996 | <li><code class="docutils literal"><span class="pre">$this->encryption->decrypt($ciphertext)</span></code><ol class="arabic"> |
| 997 | <li>Derive an encryption key and a HMAC key from your configured |
| 998 | <em>encryption_key</em> via HKDF, using the SHA-512 digest algorithm. |
| 999 | Because your configured <em>encryption_key</em> is the same, this |
| 1000 | will produce the same result as in the <code class="docutils literal"><span class="pre">encrypt()</span></code> method |
| 1001 | above - otherwise you won’t be able to decrypt it.</li> |
| 1002 | <li>Check if the string is long enough, separate the HMAC out of |
| 1003 | it and validate if it is correct (this is done in a way that |
| 1004 | prevents timing attacks against it). Return FALSE if either of |
| 1005 | the checks fails.</li> |
| 1006 | <li>Base64-decode the string.</li> |
| 1007 | <li>Separate the IV out of the cipher-text and decrypt the said |
| 1008 | cipher-text using that IV and the derived encryption key.</li> |
| 1009 | </ol> |
| 1010 | </li> |
| 1011 | </ul> |
| 1012 | </div> |
| 1013 | <div class="section" id="using-custom-parameters"> |
| 1014 | <span id="custom-parameters"></span><h4><a class="toc-backref" href="#id14">Using custom parameters</a><a class="headerlink" href="#using-custom-parameters" title="Permalink to this headline">¶</a></h4> |
| 1015 | <p>Let’s say you have to interact with another system that is out |
| 1016 | of your control and uses another method to encrypt data. A |
| 1017 | method that will most certainly not match the above-described |
| 1018 | sequence and probably not use all of the steps either.</p> |
| 1019 | <p>The Encryption library allows you to change how its encryption |
| 1020 | and decryption processes work, so that you can easily tailor a |
| 1021 | custom solution for such situations.</p> |
| 1022 | <div class="admonition note"> |
| 1023 | <p class="first admonition-title">Note</p> |
| 1024 | <p class="last">It is possible to use the library in this way, without |
| 1025 | setting an <em>encryption_key</em> in your configuration file.</p> |
| 1026 | </div> |
| 1027 | <p>All you have to do is to pass an associative array with a few |
| 1028 | parameters to either the <code class="docutils literal"><span class="pre">encrypt()</span></code> or <code class="docutils literal"><span class="pre">decrypt()</span></code> method. |
| 1029 | Here’s an example:</p> |
| 1030 | <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="c1">// Assume that we have $ciphertext, $key and $hmac_key</span> |
| 1031 | <span class="c1">// from on outside source</span> |
| 1032 | |
| 1033 | <span class="nv">$message</span> <span class="o">=</span> <span class="nv">$this</span><span class="o">-></span><span class="na">encryption</span><span class="o">-></span><span class="na">decrypt</span><span class="p">(</span> |
| 1034 | <span class="nv">$ciphertext</span><span class="p">,</span> |
| 1035 | <span class="k">array</span><span class="p">(</span> |
| 1036 | <span class="s1">'cipher'</span> <span class="o">=></span> <span class="s1">'blowfish'</span><span class="p">,</span> |
| 1037 | <span class="s1">'mode'</span> <span class="o">=></span> <span class="s1">'cbc'</span><span class="p">,</span> |
| 1038 | <span class="s1">'key'</span> <span class="o">=></span> <span class="nv">$key</span><span class="p">,</span> |
| 1039 | <span class="s1">'hmac_digest'</span> <span class="o">=></span> <span class="s1">'sha256'</span><span class="p">,</span> |
| 1040 | <span class="s1">'hmac_key'</span> <span class="o">=></span> <span class="nv">$hmac_key</span> |
| 1041 | <span class="p">)</span> |
| 1042 | <span class="p">);</span> |
| 1043 | </pre></div> |
| 1044 | </div> |
| 1045 | <p>In the above example, we are decrypting a message that was encrypted |
| 1046 | using the Blowfish cipher in CBC mode and authenticated via a SHA-256 |
| 1047 | HMAC.</p> |
| 1048 | <div class="admonition important"> |
| 1049 | <p class="first admonition-title">Important</p> |
| 1050 | <p class="last">Note that both ‘key’ and ‘hmac_key’ are used in this |
| 1051 | example. When using custom parameters, encryption and HMAC keys |
| 1052 | are not derived like the default behavior of the library is.</p> |
| 1053 | </div> |
| 1054 | <p>Below is a list of the available options.</p> |
| 1055 | <p>However, unless you really need to and you know what you are doing, |
| 1056 | we advise you to not change the encryption process as this could |
| 1057 | impact security, so please do so with caution.</p> |
| 1058 | <table border="1" class="docutils"> |
| 1059 | <colgroup> |
| 1060 | <col width="12%" /> |
| 1061 | <col width="14%" /> |
| 1062 | <col width="26%" /> |
| 1063 | <col width="49%" /> |
| 1064 | </colgroup> |
| 1065 | <thead valign="bottom"> |
| 1066 | <tr class="row-odd"><th class="head">Option</th> |
| 1067 | <th class="head">Default value</th> |
| 1068 | <th class="head">Mandatory / Optional</th> |
| 1069 | <th class="head">Description</th> |
| 1070 | </tr> |
| 1071 | </thead> |
| 1072 | <tbody valign="top"> |
| 1073 | <tr class="row-even"><td>cipher</td> |
| 1074 | <td>N/A</td> |
| 1075 | <td>Yes</td> |
| 1076 | <td>Encryption algorithm (see <a class="reference internal" href="#ciphers-and-modes"><span class="std std-ref">Supported encryption ciphers and modes</span></a>).</td> |
| 1077 | </tr> |
| 1078 | <tr class="row-odd"><td>mode</td> |
| 1079 | <td>N/A</td> |
| 1080 | <td>Yes</td> |
| 1081 | <td>Encryption mode (see <a class="reference internal" href="#encryption-modes"><span class="std std-ref">Encryption modes</span></a>).</td> |
| 1082 | </tr> |
| 1083 | <tr class="row-even"><td>key</td> |
| 1084 | <td>N/A</td> |
| 1085 | <td>Yes</td> |
| 1086 | <td>Encryption key.</td> |
| 1087 | </tr> |
| 1088 | <tr class="row-odd"><td>hmac</td> |
| 1089 | <td>TRUE</td> |
| 1090 | <td>No</td> |
| 1091 | <td>Whether to use a HMAC. |
| 1092 | Boolean. If set to FALSE, then <em>hmac_digest</em> and |
| 1093 | <em>hmac_key</em> will be ignored.</td> |
| 1094 | </tr> |
| 1095 | <tr class="row-even"><td>hmac_digest</td> |
| 1096 | <td>sha512</td> |
| 1097 | <td>No</td> |
| 1098 | <td>HMAC message digest algorithm (see <a class="reference internal" href="#digests"><span class="std std-ref">Supported HMAC authentication algorithms</span></a>).</td> |
| 1099 | </tr> |
| 1100 | <tr class="row-odd"><td>hmac_key</td> |
| 1101 | <td>N/A</td> |
| 1102 | <td>Yes, unless <em>hmac</em> is FALSE</td> |
| 1103 | <td>HMAC key.</td> |
| 1104 | </tr> |
| 1105 | <tr class="row-even"><td>raw_data</td> |
| 1106 | <td>FALSE</td> |
| 1107 | <td>No</td> |
| 1108 | <td>Whether the cipher-text should be raw. |
| 1109 | Boolean. If set to TRUE, then Base64 encoding and |
| 1110 | decoding will not be performed and HMAC will not |
| 1111 | be a hexadecimal string.</td> |
| 1112 | </tr> |
| 1113 | </tbody> |
| 1114 | </table> |
| 1115 | <div class="admonition important"> |
| 1116 | <p class="first admonition-title">Important</p> |
| 1117 | <p class="last"><code class="docutils literal"><span class="pre">encrypt()</span></code> and <code class="docutils literal"><span class="pre">decrypt()</span></code> will return FALSE if |
| 1118 | a mandatory parameter is not provided or if a provided |
| 1119 | value is incorrect. This includes <em>hmac_key</em>, unless <em>hmac</em> |
| 1120 | is set to FALSE.</p> |
| 1121 | </div> |
| 1122 | </div> |
| 1123 | <div class="section" id="supported-hmac-authentication-algorithms"> |
| 1124 | <span id="digests"></span><h4><a class="toc-backref" href="#id15">Supported HMAC authentication algorithms</a><a class="headerlink" href="#supported-hmac-authentication-algorithms" title="Permalink to this headline">¶</a></h4> |
| 1125 | <p>For HMAC message authentication, the Encryption library supports |
| 1126 | usage of the SHA-2 family of algorithms:</p> |
| 1127 | <table border="1" class="docutils"> |
| 1128 | <colgroup> |
| 1129 | <col width="19%" /> |
| 1130 | <col width="34%" /> |
| 1131 | <col width="47%" /> |
| 1132 | </colgroup> |
| 1133 | <thead valign="bottom"> |
| 1134 | <tr class="row-odd"><th class="head">Algorithm</th> |
| 1135 | <th class="head">Raw length (bytes)</th> |
| 1136 | <th class="head">Hex-encoded length (bytes)</th> |
| 1137 | </tr> |
| 1138 | </thead> |
| 1139 | <tbody valign="top"> |
| 1140 | <tr class="row-even"><td>sha512</td> |
| 1141 | <td>64</td> |
| 1142 | <td>128</td> |
| 1143 | </tr> |
| 1144 | <tr class="row-odd"><td>sha384</td> |
| 1145 | <td>48</td> |
| 1146 | <td>96</td> |
| 1147 | </tr> |
| 1148 | <tr class="row-even"><td>sha256</td> |
| 1149 | <td>32</td> |
| 1150 | <td>64</td> |
| 1151 | </tr> |
| 1152 | <tr class="row-odd"><td>sha224</td> |
| 1153 | <td>28</td> |
| 1154 | <td>56</td> |
| 1155 | </tr> |
| 1156 | </tbody> |
| 1157 | </table> |
| 1158 | <p>The reason for not including other popular algorithms, such as |
| 1159 | MD5 or SHA1 is that they are no longer considered secure enough |
| 1160 | and as such, we don’t want to encourage their usage. |
| 1161 | If you absolutely need to use them, it is easy to do so via PHP’s |
| 1162 | native <a class="reference external" href="http://php.net/manual/en/function.hash-hmac.php">hash_hmac()</a> function.</p> |
| 1163 | <p>Stronger algorithms of course will be added in the future as they |
| 1164 | appear and become widely available.</p> |
| 1165 | </div> |
| 1166 | </div> |
| 1167 | </div> |
| 1168 | <div class="section" id="class-reference"> |
| 1169 | <h2><a class="toc-backref" href="#id16">Class Reference</a><a class="headerlink" href="#class-reference" title="Permalink to this headline">¶</a></h2> |
| 1170 | <dl class="class"> |
| 1171 | <dt id="CI_Encryption"> |
| 1172 | <em class="property">class </em><code class="descname">CI_Encryption</code><a class="headerlink" href="#CI_Encryption" title="Permalink to this definition">¶</a></dt> |
| 1173 | <dd><dl class="method"> |
| 1174 | <dt id="CI_Encryption::initialize"> |
| 1175 | <code class="descname">initialize</code><span class="sig-paren">(</span><em>$params</em><span class="sig-paren">)</span><a class="headerlink" href="#CI_Encryption::initialize" title="Permalink to this definition">¶</a></dt> |
| 1176 | <dd><table class="docutils field-list" frame="void" rules="none"> |
| 1177 | <col class="field-name" /> |
| 1178 | <col class="field-body" /> |
| 1179 | <tbody valign="top"> |
| 1180 | <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> |
| 1181 | <li><strong>$params</strong> (<em>array</em>) – Configuration parameters</li> |
| 1182 | </ul> |
| 1183 | </td> |
| 1184 | </tr> |
| 1185 | <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">CI_Encryption instance (method chaining)</p> |
| 1186 | </td> |
| 1187 | </tr> |
| 1188 | <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">CI_Encryption</p> |
| 1189 | </td> |
| 1190 | </tr> |
| 1191 | </tbody> |
| 1192 | </table> |
| 1193 | <p>Initializes (configures) the library to use a different |
| 1194 | driver, cipher, mode or key.</p> |
| 1195 | <p>Example:</p> |
| 1196 | <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$this</span><span class="o">-></span><span class="na">encryption</span><span class="o">-></span><span class="na">initialize</span><span class="p">(</span> |
| 1197 | <span class="k">array</span><span class="p">(</span><span class="s1">'mode'</span> <span class="o">=></span> <span class="s1">'ctr'</span><span class="p">)</span> |
| 1198 | <span class="p">);</span> |
| 1199 | </pre></div> |
| 1200 | </div> |
| 1201 | <p>Please refer to the <a class="reference internal" href="#configuration"><span class="std std-ref">Configuring the library</span></a> section for detailed info.</p> |
| 1202 | </dd></dl> |
| 1203 | |
| 1204 | <dl class="method"> |
| 1205 | <dt id="CI_Encryption::encrypt"> |
| 1206 | <code class="descname">encrypt</code><span class="sig-paren">(</span><em>$data</em><span class="optional">[</span>, <em>$params = NULL</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#CI_Encryption::encrypt" title="Permalink to this definition">¶</a></dt> |
| 1207 | <dd><table class="docutils field-list" frame="void" rules="none"> |
| 1208 | <col class="field-name" /> |
| 1209 | <col class="field-body" /> |
| 1210 | <tbody valign="top"> |
| 1211 | <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> |
| 1212 | <li><strong>$data</strong> (<em>string</em>) – Data to encrypt</li> |
| 1213 | <li><strong>$params</strong> (<em>array</em>) – Optional parameters</li> |
| 1214 | </ul> |
| 1215 | </td> |
| 1216 | </tr> |
| 1217 | <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">Encrypted data or FALSE on failure</p> |
| 1218 | </td> |
| 1219 | </tr> |
| 1220 | <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">string</p> |
| 1221 | </td> |
| 1222 | </tr> |
| 1223 | </tbody> |
| 1224 | </table> |
| 1225 | <p>Encrypts the input data and returns its ciphertext.</p> |
| 1226 | <p>Example:</p> |
| 1227 | <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$ciphertext</span> <span class="o">=</span> <span class="nv">$this</span><span class="o">-></span><span class="na">encryption</span><span class="o">-></span><span class="na">encrypt</span><span class="p">(</span><span class="s1">'My secret message'</span><span class="p">);</span> |
| 1228 | </pre></div> |
| 1229 | </div> |
| 1230 | <p>Please refer to the <a class="reference internal" href="#custom-parameters"><span class="std std-ref">Using custom parameters</span></a> section for information |
| 1231 | on the optional parameters.</p> |
| 1232 | </dd></dl> |
| 1233 | |
| 1234 | <dl class="method"> |
| 1235 | <dt id="CI_Encryption::decrypt"> |
| 1236 | <code class="descname">decrypt</code><span class="sig-paren">(</span><em>$data</em><span class="optional">[</span>, <em>$params = NULL</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#CI_Encryption::decrypt" title="Permalink to this definition">¶</a></dt> |
| 1237 | <dd><table class="docutils field-list" frame="void" rules="none"> |
| 1238 | <col class="field-name" /> |
| 1239 | <col class="field-body" /> |
| 1240 | <tbody valign="top"> |
| 1241 | <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> |
| 1242 | <li><strong>$data</strong> (<em>string</em>) – Data to decrypt</li> |
| 1243 | <li><strong>$params</strong> (<em>array</em>) – Optional parameters</li> |
| 1244 | </ul> |
| 1245 | </td> |
| 1246 | </tr> |
| 1247 | <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">Decrypted data or FALSE on failure</p> |
| 1248 | </td> |
| 1249 | </tr> |
| 1250 | <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">string</p> |
| 1251 | </td> |
| 1252 | </tr> |
| 1253 | </tbody> |
| 1254 | </table> |
| 1255 | <p>Decrypts the input data and returns it in plain-text.</p> |
| 1256 | <p>Example:</p> |
| 1257 | <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="k">echo</span> <span class="nv">$this</span><span class="o">-></span><span class="na">encryption</span><span class="o">-></span><span class="na">decrypt</span><span class="p">(</span><span class="nv">$ciphertext</span><span class="p">);</span> |
| 1258 | </pre></div> |
| 1259 | </div> |
| 1260 | <p>Please refer to the <a class="reference internal" href="#custom-parameters"><span class="std std-ref">Using custom parameters</span></a> secrion for information |
| 1261 | on the optional parameters.</p> |
| 1262 | </dd></dl> |
| 1263 | |
| 1264 | <dl class="method"> |
| 1265 | <dt id="CI_Encryption::create_key"> |
| 1266 | <code class="descname">create_key</code><span class="sig-paren">(</span><em>$length</em><span class="sig-paren">)</span><a class="headerlink" href="#CI_Encryption::create_key" title="Permalink to this definition">¶</a></dt> |
| 1267 | <dd><table class="docutils field-list" frame="void" rules="none"> |
| 1268 | <col class="field-name" /> |
| 1269 | <col class="field-body" /> |
| 1270 | <tbody valign="top"> |
| 1271 | <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> |
| 1272 | <li><strong>$length</strong> (<em>int</em>) – Output length</li> |
| 1273 | </ul> |
| 1274 | </td> |
| 1275 | </tr> |
| 1276 | <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">A pseudo-random cryptographic key with the specified length, or FALSE on failure</p> |
| 1277 | </td> |
| 1278 | </tr> |
| 1279 | <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">string</p> |
| 1280 | </td> |
| 1281 | </tr> |
| 1282 | </tbody> |
| 1283 | </table> |
| 1284 | <p>Creates a cryptographic key by fetching random data from |
| 1285 | the operating system’s sources (i.e. /dev/urandom).</p> |
| 1286 | </dd></dl> |
| 1287 | |
| 1288 | <dl class="method"> |
| 1289 | <dt id="CI_Encryption::hkdf"> |
| 1290 | <code class="descname">hkdf</code><span class="sig-paren">(</span><em>$key</em><span class="optional">[</span>, <em>$digest = 'sha512'</em><span class="optional">[</span>, <em>$salt = NULL</em><span class="optional">[</span>, <em>$length = NULL</em><span class="optional">[</span>, <em>$info = ''</em><span class="optional">]</span><span class="optional">]</span><span class="optional">]</span><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#CI_Encryption::hkdf" title="Permalink to this definition">¶</a></dt> |
| 1291 | <dd><table class="docutils field-list" frame="void" rules="none"> |
| 1292 | <col class="field-name" /> |
| 1293 | <col class="field-body" /> |
| 1294 | <tbody valign="top"> |
| 1295 | <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> |
| 1296 | <li><strong>$key</strong> (<em>string</em>) – Input key material</li> |
| 1297 | <li><strong>$digest</strong> (<em>string</em>) – A SHA-2 family digest algorithm</li> |
| 1298 | <li><strong>$salt</strong> (<em>string</em>) – Optional salt</li> |
| 1299 | <li><strong>$length</strong> (<em>int</em>) – Optional output length</li> |
| 1300 | <li><strong>$info</strong> (<em>string</em>) – Optional context/application-specific info</li> |
| 1301 | </ul> |
| 1302 | </td> |
| 1303 | </tr> |
| 1304 | <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">A pseudo-random key or FALSE on failure</p> |
| 1305 | </td> |
| 1306 | </tr> |
| 1307 | <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">string</p> |
| 1308 | </td> |
| 1309 | </tr> |
| 1310 | </tbody> |
| 1311 | </table> |
| 1312 | <p>Derives a key from another, presumably weaker key.</p> |
| 1313 | <p>This method is used internally to derive an encryption and HMAC key |
| 1314 | from your configured <em>encryption_key</em>.</p> |
| 1315 | <p>It is publicly available due to its otherwise general purpose. It is |
| 1316 | described in <a class="reference external" href="https://tools.ietf.org/rfc/rfc5869.txt">RFC 5869</a>.</p> |
| 1317 | <p>However, as opposed to the description in RFC 5869, this implementation |
| 1318 | doesn’t support SHA1.</p> |
| 1319 | <p>Example:</p> |
| 1320 | <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$hmac_key</span> <span class="o">=</span> <span class="nv">$this</span><span class="o">-></span><span class="na">encryption</span><span class="o">-></span><span class="na">hkdf</span><span class="p">(</span> |
| 1321 | <span class="nv">$key</span><span class="p">,</span> |
| 1322 | <span class="s1">'sha512'</span><span class="p">,</span> |
| 1323 | <span class="k">NULL</span><span class="p">,</span> |
| 1324 | <span class="k">NULL</span><span class="p">,</span> |
| 1325 | <span class="s1">'authentication'</span> |
| 1326 | <span class="p">);</span> |
| 1327 | |
| 1328 | <span class="c1">// $hmac_key is a pseudo-random key with a length of 64 bytes</span> |
| 1329 | </pre></div> |
| 1330 | </div> |
| 1331 | </dd></dl> |
| 1332 | |
| 1333 | </dd></dl> |
| 1334 | |
| 1335 | </div> |
| 1336 | </div> |
| 1337 | |
| 1338 | |
| 1339 | </div> |
| 1340 | <footer> |
| 1341 | |
| 1342 | <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation"> |
| 1343 | |
| 1344 | <a href="file_uploading.html" class="btn btn-neutral float-right" title="File Uploading Class">Next <span class="fa fa-arrow-circle-right"></span></a> |
| 1345 | |
| 1346 | |
| 1347 | <a href="encrypt.html" class="btn btn-neutral" title="Encrypt Class"><span class="fa fa-arrow-circle-left"></span> Previous</a> |
| 1348 | |
| 1349 | </div> |
| 1350 | |
| 1351 | |
| 1352 | <hr/> |
| 1353 | |
| 1354 | <div role="contentinfo"> |
| 1355 | <p> |
| 1356 | © Copyright 2014 - 2019, British Columbia Institute of Technology. |
| 1357 | Last updated on Jan 16, 2019. |
| 1358 | </p> |
| 1359 | </div> |
| 1360 | |
| 1361 | Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/snide/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>. |
| 1362 | |
| 1363 | </footer> |
| 1364 | </div> |
| 1365 | </div> |
| 1366 | |
| 1367 | </section> |
| 1368 | |
| 1369 | </div> |
| 1370 | |
| 1371 | |
| 1372 | |
| 1373 | |
| 1374 | |
| 1375 | <script type="text/javascript"> |
| 1376 | var DOCUMENTATION_OPTIONS = { |
| 1377 | URL_ROOT:'../', |
| 1378 | VERSION:'3.1.10', |
| 1379 | COLLAPSE_INDEX:false, |
| 1380 | FILE_SUFFIX:'.html', |
| 1381 | HAS_SOURCE: false |
| 1382 | }; |
| 1383 | </script> |
| 1384 | <script type="text/javascript" src="../_static/jquery.js"></script> |
| 1385 | <script type="text/javascript" src="../_static/underscore.js"></script> |
| 1386 | <script type="text/javascript" src="../_static/doctools.js"></script> |
| 1387 | |
| 1388 | |
| 1389 | |
| 1390 | |
| 1391 | |
| 1392 | <script type="text/javascript" src="../_static/js/theme.js"></script> |
| 1393 | |
| 1394 | |
| 1395 | |
| 1396 | |
| 1397 | <script type="text/javascript"> |
| 1398 | jQuery(function () { |
| 1399 | SphinxRtdTheme.StickyNav.enable(); |
| 1400 | }); |
| 1401 | </script> |
| 1402 | |
| 1403 | |
| 1404 | </body> |
| 1405 | </html> |