-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_encryption_8php_source.html
100 lines (98 loc) · 37 KB
/
_encryption_8php_source.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.13"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>GravityView: Encryption.php Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="custom-doxygen.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr style="height: 56px;">
<td id="projectlogo"><img alt="Logo" src="logo.png"/></td>
<td id="projectalign" style="padding-left: 0.5em;">
<div id="projectname">GravityView
 <span id="projectnumber">2.17</span>
</div>
<div id="projectbrief">The best, easiest way to display Gravity Forms entries on your website.</div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.13 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
$(function() {
initMenu('',true,false,'search.php','Search');
$(document).ready(function() { init_search(); });
});
</script>
<div id="main-nav"></div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>
<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0"
name="MSearchResults" id="MSearchResults">
</iframe>
</div>
<div id="nav-path" class="navpath">
<ul>
<li class="navelem"><a class="el" href="dir_c18ef6374e5a604878aeced0c5671a4f.html">vendor_prefixed</a></li><li class="navelem"><a class="el" href="dir_86b19f5df6747de098149f7d19a9f494.html">gravitykit</a></li><li class="navelem"><a class="el" href="dir_cef91bdb3eb284f59d80e56ba3584b5f.html">foundation</a></li><li class="navelem"><a class="el" href="dir_43934aaf9842616eb4dc1cec03c6d866.html">src</a></li><li class="navelem"><a class="el" href="dir_8a0c57d1043a8653cea61894127f3a88.html">Encryption</a></li> </ul>
</div>
</div><!-- top -->
<div class="header">
<div class="headertitle">
<div class="title">Encryption.php</div> </div>
</div><!--header-->
<div class="contents">
<a href="_encryption_8php.html">Go to the documentation of this file.</a><div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno"> 1</span> <?php<span class="comment"></span></div><div class="line"><a name="l00002"></a><span class="lineno"> 2</span> <span class="comment">/**</span></div><div class="line"><a name="l00003"></a><span class="lineno"> 3</span> <span class="comment"> * @license GPL-2.0-or-later</span></div><div class="line"><a name="l00004"></a><span class="lineno"> 4</span> <span class="comment"> *</span></div><div class="line"><a name="l00005"></a><span class="lineno"> 5</span> <span class="comment"> * Modified by gravityview on 13-January-2023 using Strauss.</span></div><div class="line"><a name="l00006"></a><span class="lineno"> 6</span> <span class="comment"> * @see https://github.com/BrianHenryIE/strauss</span></div><div class="line"><a name="l00007"></a><span class="lineno"> 7</span> <span class="comment"> */</span></div><div class="line"><a name="l00008"></a><span class="lineno"> 8</span> </div><div class="line"><a name="l00009"></a><span class="lineno"><a class="line" href="namespace_gravity_kit_1_1_gravity_view_1_1_foundation_1_1_encryption.html"> 9</a></span> <span class="keyword">namespace </span><a class="code" href="namespace_gravity_kit_1_1_gravity_view_1_1_foundation_1_1_encryption.html">GravityKit\GravityView\Foundation\Encryption</a>;</div><div class="line"><a name="l00010"></a><span class="lineno"> 10</span> </div><div class="line"><a name="l00011"></a><span class="lineno"> 11</span> use <a class="code" href="namespace_exception.html">Exception</a>;</div><div class="line"><a name="l00012"></a><span class="lineno"> 12</span> <span class="comment"></span></div><div class="line"><a name="l00013"></a><span class="lineno"> 13</span> <span class="comment">/**</span></div><div class="line"><a name="l00014"></a><span class="lineno"> 14</span> <span class="comment"> * This class provides basic data encryption functionality.</span></div><div class="line"><a name="l00015"></a><span class="lineno"> 15</span> <span class="comment"> */</span></div><div class="line"><a name="l00016"></a><span class="lineno"><a class="line" href="class_gravity_kit_1_1_gravity_view_1_1_foundation_1_1_encryption_1_1_encryption.html"> 16</a></span> <span class="keyword">class </span><a class="code" href="class_gravity_kit_1_1_gravity_view_1_1_foundation_1_1_encryption_1_1_encryption.html">Encryption</a> {</div><div class="line"><a name="l00017"></a><span class="lineno"><a class="line" href="class_gravity_kit_1_1_gravity_view_1_1_foundation_1_1_encryption_1_1_encryption.html#a223259a5bedcd69a68d61f40326243e6"> 17</a></span>  <span class="keyword">const</span> <a class="code" href="class_gravity_kit_1_1_gravity_view_1_1_foundation_1_1_encryption_1_1_encryption.html#a223259a5bedcd69a68d61f40326243e6">DEFAULT_NONCE</a> = <span class="stringliteral">'bc5d92ffc6c54ff8d865a1e6f3361f48d0a84a2b145be34e'</span>; <span class="comment">// 24-bit value stored as a hex string</span></div><div class="line"><a name="l00018"></a><span class="lineno"> 18</span> <span class="comment"></span></div><div class="line"><a name="l00019"></a><span class="lineno"> 19</span> <span class="comment"> /**</span></div><div class="line"><a name="l00020"></a><span class="lineno"> 20</span> <span class="comment"> * @since 1.0.0</span></div><div class="line"><a name="l00021"></a><span class="lineno"> 21</span> <span class="comment"> *</span></div><div class="line"><a name="l00022"></a><span class="lineno"> 22</span> <span class="comment"> * @var Encryption Class instance.</span></div><div class="line"><a name="l00023"></a><span class="lineno"> 23</span> <span class="comment"> */</span></div><div class="line"><a name="l00024"></a><span class="lineno"><a class="line" href="class_gravity_kit_1_1_gravity_view_1_1_foundation_1_1_encryption_1_1_encryption.html#ac350be23da328a6f5429313efc9b96e4"> 24</a></span>  <span class="keyword">private</span> <span class="keyword">static</span> <a class="code" href="class_gravity_kit_1_1_gravity_view_1_1_foundation_1_1_encryption_1_1_encryption.html#ac350be23da328a6f5429313efc9b96e4">$_instance</a>;</div><div class="line"><a name="l00025"></a><span class="lineno"> 25</span> <span class="comment"></span></div><div class="line"><a name="l00026"></a><span class="lineno"> 26</span> <span class="comment"> /**</span></div><div class="line"><a name="l00027"></a><span class="lineno"> 27</span> <span class="comment"> * @since 1.0.0</span></div><div class="line"><a name="l00028"></a><span class="lineno"> 28</span> <span class="comment"> *</span></div><div class="line"><a name="l00029"></a><span class="lineno"> 29</span> <span class="comment"> * @var string Secret key used to encrypt license key.</span></div><div class="line"><a name="l00030"></a><span class="lineno"> 30</span> <span class="comment"> */</span></div><div class="line"><a name="l00031"></a><span class="lineno"><a class="line" href="class_gravity_kit_1_1_gravity_view_1_1_foundation_1_1_encryption_1_1_encryption.html#a0dcac6065fa86fa59bfed5a17c3fed8e"> 31</a></span>  <span class="keyword">private</span> <a class="code" href="class_gravity_kit_1_1_gravity_view_1_1_foundation_1_1_encryption_1_1_encryption.html#a0dcac6065fa86fa59bfed5a17c3fed8e">$_secret_key</a>;</div><div class="line"><a name="l00032"></a><span class="lineno"> 32</span> <span class="comment"></span></div><div class="line"><a name="l00033"></a><span class="lineno"> 33</span> <span class="comment"> /**</span></div><div class="line"><a name="l00034"></a><span class="lineno"> 34</span> <span class="comment"> * Class constructor.</span></div><div class="line"><a name="l00035"></a><span class="lineno"> 35</span> <span class="comment"> *</span></div><div class="line"><a name="l00036"></a><span class="lineno"> 36</span> <span class="comment"> * @since 1.0.0</span></div><div class="line"><a name="l00037"></a><span class="lineno"> 37</span> <span class="comment"> *</span></div><div class="line"><a name="l00038"></a><span class="lineno"> 38</span> <span class="comment"> * @param string $secret_key (optional) Secret key to be used for encryption. Default: wp_salt() value.</span></div><div class="line"><a name="l00039"></a><span class="lineno"> 39</span> <span class="comment"> *</span></div><div class="line"><a name="l00040"></a><span class="lineno"> 40</span> <span class="comment"> * @return void</span></div><div class="line"><a name="l00041"></a><span class="lineno"> 41</span> <span class="comment"> */</span></div><div class="line"><a name="l00042"></a><span class="lineno"><a class="line" href="class_gravity_kit_1_1_gravity_view_1_1_foundation_1_1_encryption_1_1_encryption.html#a4c0287736c619635d450c370ae86a10b"> 42</a></span>  <span class="keyword">private</span> <span class="keyword">function</span> <a class="code" href="class_gravity_kit_1_1_gravity_view_1_1_foundation_1_1_encryption_1_1_encryption.html#a4c0287736c619635d450c370ae86a10b">__construct</a>( $secret_key = <span class="stringliteral">''</span> ) {</div><div class="line"><a name="l00043"></a><span class="lineno"> 43</span>  <span class="keywordflow">if</span> ( ! $secret_key ) {</div><div class="line"><a name="l00044"></a><span class="lineno"> 44</span>  $secret_key = wp_salt();</div><div class="line"><a name="l00045"></a><span class="lineno"> 45</span>  }</div><div class="line"><a name="l00046"></a><span class="lineno"> 46</span> </div><div class="line"><a name="l00047"></a><span class="lineno"> 47</span>  <span class="keywordflow">if</span> ( strlen( $secret_key ) < SODIUM_CRYPTO_SECRETBOX_KEYBYTES ) {</div><div class="line"><a name="l00048"></a><span class="lineno"> 48</span>  $secret_key = hash_hmac( <span class="stringliteral">'sha256'</span>, $secret_key, self::DEFAULT_NONCE );</div><div class="line"><a name="l00049"></a><span class="lineno"> 49</span>  }</div><div class="line"><a name="l00050"></a><span class="lineno"> 50</span> </div><div class="line"><a name="l00051"></a><span class="lineno"> 51</span>  <span class="keywordflow">if</span> ( strlen( $secret_key ) > SODIUM_CRYPTO_SECRETBOX_KEYBYTES ) {</div><div class="line"><a name="l00052"></a><span class="lineno"> 52</span>  $secret_key = mb_substr( $secret_key, 0, SODIUM_CRYPTO_SECRETBOX_KEYBYTES, <span class="stringliteral">'8bit'</span> );</div><div class="line"><a name="l00053"></a><span class="lineno"> 53</span>  }</div><div class="line"><a name="l00054"></a><span class="lineno"> 54</span> </div><div class="line"><a name="l00055"></a><span class="lineno"> 55</span>  $this->_secret_key = $secret_key;</div><div class="line"><a name="l00056"></a><span class="lineno"> 56</span>  }</div><div class="line"><a name="l00057"></a><span class="lineno"> 57</span> <span class="comment"></span></div><div class="line"><a name="l00058"></a><span class="lineno"> 58</span> <span class="comment"> /**</span></div><div class="line"><a name="l00059"></a><span class="lineno"> 59</span> <span class="comment"> * Returns class instance.</span></div><div class="line"><a name="l00060"></a><span class="lineno"> 60</span> <span class="comment"> *</span></div><div class="line"><a name="l00061"></a><span class="lineno"> 61</span> <span class="comment"> * @since 1.0.0</span></div><div class="line"><a name="l00062"></a><span class="lineno"> 62</span> <span class="comment"> *</span></div><div class="line"><a name="l00063"></a><span class="lineno"> 63</span> <span class="comment"> * @param string $secret_key (optional) Secret key to be used for encryption. Default: wp_salt() value.</span></div><div class="line"><a name="l00064"></a><span class="lineno"> 64</span> <span class="comment"> *</span></div><div class="line"><a name="l00065"></a><span class="lineno"> 65</span> <span class="comment"> * @return Encryption</span></div><div class="line"><a name="l00066"></a><span class="lineno"> 66</span> <span class="comment"> */</span></div><div class="line"><a name="l00067"></a><span class="lineno"><a class="line" href="class_gravity_kit_1_1_gravity_view_1_1_foundation_1_1_encryption_1_1_encryption.html#afd0a3e9021de0ca766baecac9988efc8"> 67</a></span>  <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">function</span> <a class="code" href="class_gravity_kit_1_1_gravity_view_1_1_foundation_1_1_encryption_1_1_encryption.html#afd0a3e9021de0ca766baecac9988efc8">get_instance</a>( $secret_key = <span class="stringliteral">''</span> ) {</div><div class="line"><a name="l00068"></a><span class="lineno"> 68</span>  <span class="keywordflow">if</span> ( is_null( self::$_instance ) ) {</div><div class="line"><a name="l00069"></a><span class="lineno"> 69</span>  self::$_instance = <span class="keyword">new</span> <span class="keyword">self</span>( $secret_key );</div><div class="line"><a name="l00070"></a><span class="lineno"> 70</span>  }</div><div class="line"><a name="l00071"></a><span class="lineno"> 71</span> </div><div class="line"><a name="l00072"></a><span class="lineno"> 72</span>  <span class="keywordflow">return</span> self::$_instance;</div><div class="line"><a name="l00073"></a><span class="lineno"> 73</span>  }</div><div class="line"><a name="l00074"></a><span class="lineno"> 74</span> <span class="comment"></span></div><div class="line"><a name="l00075"></a><span class="lineno"> 75</span> <span class="comment"> /**</span></div><div class="line"><a name="l00076"></a><span class="lineno"> 76</span> <span class="comment"> * Encrypts data.</span></div><div class="line"><a name="l00077"></a><span class="lineno"> 77</span> <span class="comment"> *</span></div><div class="line"><a name="l00078"></a><span class="lineno"> 78</span> <span class="comment"> * Note: This is for basic internal use and is not intended for highly-sensitive applications.</span></div><div class="line"><a name="l00079"></a><span class="lineno"> 79</span> <span class="comment"> *</span></div><div class="line"><a name="l00080"></a><span class="lineno"> 80</span> <span class="comment"> * @since 1.0.0</span></div><div class="line"><a name="l00081"></a><span class="lineno"> 81</span> <span class="comment"> *</span></div><div class="line"><a name="l00082"></a><span class="lineno"> 82</span> <span class="comment"> * @param string $data Data to encrypt.</span></div><div class="line"><a name="l00083"></a><span class="lineno"> 83</span> <span class="comment"> * @param bool $use_random_nonce (optional) Whether to use random nonce. Default: true.</span></div><div class="line"><a name="l00084"></a><span class="lineno"> 84</span> <span class="comment"> * @param string|null $custom_nonce (optional) Custom IV value to use. Default: null.</span></div><div class="line"><a name="l00085"></a><span class="lineno"> 85</span> <span class="comment"> *</span></div><div class="line"><a name="l00086"></a><span class="lineno"> 86</span> <span class="comment"> * @return false|mixed|string</span></div><div class="line"><a name="l00087"></a><span class="lineno"> 87</span> <span class="comment"> */</span></div><div class="line"><a name="l00088"></a><span class="lineno"><a class="line" href="class_gravity_kit_1_1_gravity_view_1_1_foundation_1_1_encryption_1_1_encryption.html#a6094445dc2f48d3e9cb94c2d80075a5d"> 88</a></span>  <span class="keyword">public</span> <span class="keyword">function</span> <a class="code" href="class_gravity_kit_1_1_gravity_view_1_1_foundation_1_1_encryption_1_1_encryption.html#a6094445dc2f48d3e9cb94c2d80075a5d">encrypt</a>( $data, $use_random_nonce = <span class="keyword">true</span>, $custom_nonce = null ) {</div><div class="line"><a name="l00089"></a><span class="lineno"> 89</span>  <span class="keywordflow">try</span> {</div><div class="line"><a name="l00090"></a><span class="lineno"> 90</span>  <span class="keywordflow">if</span> ( ! $use_random_nonce ) {</div><div class="line"><a name="l00091"></a><span class="lineno"> 91</span>  $nonce = $custom_nonce ? $custom_nonce : sodium_hex2bin( self::DEFAULT_NONCE );</div><div class="line"><a name="l00092"></a><span class="lineno"> 92</span>  } <span class="keywordflow">else</span> {</div><div class="line"><a name="l00093"></a><span class="lineno"> 93</span>  $nonce = $this-><a class="code" href="class_gravity_kit_1_1_gravity_view_1_1_foundation_1_1_encryption_1_1_encryption.html#a09cf31347f486a69d1a5311aec9cd49d">get_random_nonce</a>();</div><div class="line"><a name="l00094"></a><span class="lineno"> 94</span>  }</div><div class="line"><a name="l00095"></a><span class="lineno"> 95</span>  } <span class="keywordflow">catch</span> ( <a class="code" href="namespace_exception.html">Exception</a> $e ) {</div><div class="line"><a name="l00096"></a><span class="lineno"> 96</span>  <span class="keywordflow">return</span> <span class="keyword">false</span>;</div><div class="line"><a name="l00097"></a><span class="lineno"> 97</span>  }</div><div class="line"><a name="l00098"></a><span class="lineno"> 98</span> </div><div class="line"><a name="l00099"></a><span class="lineno"> 99</span>  <span class="keywordflow">if</span> ( strlen( $nonce ) < SODIUM_CRYPTO_SECRETBOX_NONCEBYTES ) {</div><div class="line"><a name="l00100"></a><span class="lineno"> 100</span>  $nonce = hash_hmac( <span class="stringliteral">'sha256'</span>, $nonce, self::DEFAULT_NONCE );</div><div class="line"><a name="l00101"></a><span class="lineno"> 101</span>  }</div><div class="line"><a name="l00102"></a><span class="lineno"> 102</span> </div><div class="line"><a name="l00103"></a><span class="lineno"> 103</span>  <span class="keywordflow">if</span> ( strlen( $nonce ) > SODIUM_CRYPTO_SECRETBOX_KEYBYTES ) {</div><div class="line"><a name="l00104"></a><span class="lineno"> 104</span>  $nonce = mb_substr( $nonce, 0, SODIUM_CRYPTO_SECRETBOX_NONCEBYTES, <span class="stringliteral">'8bit'</span> );</div><div class="line"><a name="l00105"></a><span class="lineno"> 105</span>  }</div><div class="line"><a name="l00106"></a><span class="lineno"> 106</span> </div><div class="line"><a name="l00107"></a><span class="lineno"> 107</span>  <span class="keywordflow">try</span> {</div><div class="line"><a name="l00108"></a><span class="lineno"> 108</span>  $encrypted = sodium_crypto_secretbox( $data, $nonce, $this->_secret_key );</div><div class="line"><a name="l00109"></a><span class="lineno"> 109</span>  $encrypted = sodium_bin2base64( $nonce . $encrypted, SODIUM_BASE64_VARIANT_ORIGINAL );</div><div class="line"><a name="l00110"></a><span class="lineno"> 110</span>  <span class="keywordflow">if</span> ( extension_loaded( <span class="stringliteral">'sodium'</span> ) || extension_loaded( <span class="stringliteral">'libsodium'</span> ) ) {</div><div class="line"><a name="l00111"></a><span class="lineno"> 111</span>  sodium_memzero( $nonce );</div><div class="line"><a name="l00112"></a><span class="lineno"> 112</span>  }</div><div class="line"><a name="l00113"></a><span class="lineno"> 113</span>  } <span class="keywordflow">catch</span> ( <a class="code" href="namespace_exception.html">Exception</a> $e ) {</div><div class="line"><a name="l00114"></a><span class="lineno"> 114</span>  <span class="keywordflow">return</span> <span class="keyword">false</span>;</div><div class="line"><a name="l00115"></a><span class="lineno"> 115</span>  }</div><div class="line"><a name="l00116"></a><span class="lineno"> 116</span> </div><div class="line"><a name="l00117"></a><span class="lineno"> 117</span>  <span class="keywordflow">return</span> $encrypted;</div><div class="line"><a name="l00118"></a><span class="lineno"> 118</span>  }</div><div class="line"><a name="l00119"></a><span class="lineno"> 119</span> <span class="comment"></span></div><div class="line"><a name="l00120"></a><span class="lineno"> 120</span> <span class="comment"> /**</span></div><div class="line"><a name="l00121"></a><span class="lineno"> 121</span> <span class="comment"> * Decrypts data.</span></div><div class="line"><a name="l00122"></a><span class="lineno"> 122</span> <span class="comment"> *</span></div><div class="line"><a name="l00123"></a><span class="lineno"> 123</span> <span class="comment"> * Note: This is for internal use and is not intended for highly-sensitive applications.</span></div><div class="line"><a name="l00124"></a><span class="lineno"> 124</span> <span class="comment"> *</span></div><div class="line"><a name="l00125"></a><span class="lineno"> 125</span> <span class="comment"> * @since 1.0.0</span></div><div class="line"><a name="l00126"></a><span class="lineno"> 126</span> <span class="comment"> *</span></div><div class="line"><a name="l00127"></a><span class="lineno"> 127</span> <span class="comment"> * @param string $data Data to encrypt.</span></div><div class="line"><a name="l00128"></a><span class="lineno"> 128</span> <span class="comment"> *</span></div><div class="line"><a name="l00129"></a><span class="lineno"> 129</span> <span class="comment"> * @return string|null</span></div><div class="line"><a name="l00130"></a><span class="lineno"> 130</span> <span class="comment"> */</span></div><div class="line"><a name="l00131"></a><span class="lineno"><a class="line" href="class_gravity_kit_1_1_gravity_view_1_1_foundation_1_1_encryption_1_1_encryption.html#a262c2478ac92061132e08deee82dd405"> 131</a></span>  <span class="keyword">public</span> <span class="keyword">function</span> <a class="code" href="class_gravity_kit_1_1_gravity_view_1_1_foundation_1_1_encryption_1_1_encryption.html#a262c2478ac92061132e08deee82dd405">decrypt</a>( $data ) {</div><div class="line"><a name="l00132"></a><span class="lineno"> 132</span>  <span class="keywordflow">try</span> {</div><div class="line"><a name="l00133"></a><span class="lineno"> 133</span>  $encrypted = sodium_base642bin( $data, SODIUM_BASE64_VARIANT_ORIGINAL );</div><div class="line"><a name="l00134"></a><span class="lineno"> 134</span>  } <span class="keywordflow">catch</span> ( <a class="code" href="namespace_exception.html">Exception</a> $e ) {</div><div class="line"><a name="l00135"></a><span class="lineno"> 135</span>  <span class="keywordflow">return</span> null;</div><div class="line"><a name="l00136"></a><span class="lineno"> 136</span>  }</div><div class="line"><a name="l00137"></a><span class="lineno"> 137</span> </div><div class="line"><a name="l00138"></a><span class="lineno"> 138</span>  $nonce = mb_substr( $encrypted, 0, SODIUM_CRYPTO_SECRETBOX_NONCEBYTES, <span class="stringliteral">'8bit'</span> );</div><div class="line"><a name="l00139"></a><span class="lineno"> 139</span>  $encrypted = mb_substr( $encrypted, SODIUM_CRYPTO_SECRETBOX_NONCEBYTES, null, <span class="stringliteral">'8bit'</span> );</div><div class="line"><a name="l00140"></a><span class="lineno"> 140</span> </div><div class="line"><a name="l00141"></a><span class="lineno"> 141</span>  <span class="keywordflow">try</span> {</div><div class="line"><a name="l00142"></a><span class="lineno"> 142</span>  $decrypted = sodium_crypto_secretbox_open( $encrypted, $nonce, $this->_secret_key );</div><div class="line"><a name="l00143"></a><span class="lineno"> 143</span>  } <span class="keywordflow">catch</span> ( <a class="code" href="namespace_exception.html">Exception</a> $e ) {</div><div class="line"><a name="l00144"></a><span class="lineno"> 144</span>  <span class="keywordflow">return</span> null;</div><div class="line"><a name="l00145"></a><span class="lineno"> 145</span>  }</div><div class="line"><a name="l00146"></a><span class="lineno"> 146</span> </div><div class="line"><a name="l00147"></a><span class="lineno"> 147</span>  <span class="keywordflow">return</span> $decrypted !== <span class="keyword">false</span> ? $decrypted : null;</div><div class="line"><a name="l00148"></a><span class="lineno"> 148</span>  }</div><div class="line"><a name="l00149"></a><span class="lineno"> 149</span> <span class="comment"></span></div><div class="line"><a name="l00150"></a><span class="lineno"> 150</span> <span class="comment"> /**</span></div><div class="line"><a name="l00151"></a><span class="lineno"> 151</span> <span class="comment"> * Generates a quick one-way hash of data.</span></div><div class="line"><a name="l00152"></a><span class="lineno"> 152</span> <span class="comment"> *</span></div><div class="line"><a name="l00153"></a><span class="lineno"> 153</span> <span class="comment"> * Note: This is for internal use and is not intended for highly-sensitive applications.</span></div><div class="line"><a name="l00154"></a><span class="lineno"> 154</span> <span class="comment"> *</span></div><div class="line"><a name="l00155"></a><span class="lineno"> 155</span> <span class="comment"> * @since 1.0.0</span></div><div class="line"><a name="l00156"></a><span class="lineno"> 156</span> <span class="comment"> *</span></div><div class="line"><a name="l00157"></a><span class="lineno"> 157</span> <span class="comment"> * @param string $data The data to create a hash of.</span></div><div class="line"><a name="l00158"></a><span class="lineno"> 158</span> <span class="comment"> *</span></div><div class="line"><a name="l00159"></a><span class="lineno"> 159</span> <span class="comment"> * @return string The hash.</span></div><div class="line"><a name="l00160"></a><span class="lineno"> 160</span> <span class="comment"> */</span></div><div class="line"><a name="l00161"></a><span class="lineno"><a class="line" href="class_gravity_kit_1_1_gravity_view_1_1_foundation_1_1_encryption_1_1_encryption.html#a5b156806bede6d94bb3c2d8eb06b7999"> 161</a></span>  <span class="keyword">public</span> <span class="keyword">function</span> <a class="code" href="class_gravity_kit_1_1_gravity_view_1_1_foundation_1_1_encryption_1_1_encryption.html#a5b156806bede6d94bb3c2d8eb06b7999">hash</a>( $data ) {</div><div class="line"><a name="l00162"></a><span class="lineno"> 162</span>  <span class="keywordflow">return</span> hash_hmac( <span class="stringliteral">'sha256'</span>, $data, self::DEFAULT_NONCE );</div><div class="line"><a name="l00163"></a><span class="lineno"> 163</span>  }</div><div class="line"><a name="l00164"></a><span class="lineno"> 164</span> <span class="comment"></span></div><div class="line"><a name="l00165"></a><span class="lineno"> 165</span> <span class="comment"> /**</span></div><div class="line"><a name="l00166"></a><span class="lineno"> 166</span> <span class="comment"> * Returns a random 24-byte nonce.</span></div><div class="line"><a name="l00167"></a><span class="lineno"> 167</span> <span class="comment"> *</span></div><div class="line"><a name="l00168"></a><span class="lineno"> 168</span> <span class="comment"> * @since 1.0.0</span></div><div class="line"><a name="l00169"></a><span class="lineno"> 169</span> <span class="comment"> *</span></div><div class="line"><a name="l00170"></a><span class="lineno"> 170</span> <span class="comment"> * @throws Exception</span></div><div class="line"><a name="l00171"></a><span class="lineno"> 171</span> <span class="comment"> *</span></div><div class="line"><a name="l00172"></a><span class="lineno"> 172</span> <span class="comment"> * @return string</span></div><div class="line"><a name="l00173"></a><span class="lineno"> 173</span> <span class="comment"> */</span></div><div class="line"><a name="l00174"></a><span class="lineno"><a class="line" href="class_gravity_kit_1_1_gravity_view_1_1_foundation_1_1_encryption_1_1_encryption.html#a09cf31347f486a69d1a5311aec9cd49d"> 174</a></span>  <span class="keyword">public</span> <span class="keyword">function</span> <a class="code" href="class_gravity_kit_1_1_gravity_view_1_1_foundation_1_1_encryption_1_1_encryption.html#a09cf31347f486a69d1a5311aec9cd49d">get_random_nonce</a>() {</div><div class="line"><a name="l00175"></a><span class="lineno"> 175</span>  <span class="keywordflow">return</span> random_bytes( SODIUM_CRYPTO_SECRETBOX_NONCEBYTES );</div><div class="line"><a name="l00176"></a><span class="lineno"> 176</span>  }</div><div class="line"><a name="l00177"></a><span class="lineno"> 177</span> }</div><div class="ttc" id="class_gravity_kit_1_1_gravity_view_1_1_foundation_1_1_encryption_1_1_encryption_html_a5b156806bede6d94bb3c2d8eb06b7999"><div class="ttname"><a href="class_gravity_kit_1_1_gravity_view_1_1_foundation_1_1_encryption_1_1_encryption.html#a5b156806bede6d94bb3c2d8eb06b7999">GravityKit\GravityView\Foundation\Encryption\Encryption\hash</a></div><div class="ttdeci">hash( $data)</div><div class="ttdoc">Generates a quick one-way hash of data. </div><div class="ttdef"><b>Definition:</b> <a href="_encryption_8php_source.html#l00161">Encryption.php:161</a></div></div>
<div class="ttc" id="class_gravity_kit_1_1_gravity_view_1_1_foundation_1_1_encryption_1_1_encryption_html_a4c0287736c619635d450c370ae86a10b"><div class="ttname"><a href="class_gravity_kit_1_1_gravity_view_1_1_foundation_1_1_encryption_1_1_encryption.html#a4c0287736c619635d450c370ae86a10b">GravityKit\GravityView\Foundation\Encryption\Encryption\__construct</a></div><div class="ttdeci">__construct( $secret_key='')</div><div class="ttdoc">Class constructor. </div><div class="ttdef"><b>Definition:</b> <a href="_encryption_8php_source.html#l00042">Encryption.php:42</a></div></div>
<div class="ttc" id="class_gravity_kit_1_1_gravity_view_1_1_foundation_1_1_encryption_1_1_encryption_html_ac350be23da328a6f5429313efc9b96e4"><div class="ttname"><a href="class_gravity_kit_1_1_gravity_view_1_1_foundation_1_1_encryption_1_1_encryption.html#ac350be23da328a6f5429313efc9b96e4">GravityKit\GravityView\Foundation\Encryption\Encryption\$_instance</a></div><div class="ttdeci">static $_instance</div><div class="ttdef"><b>Definition:</b> <a href="_encryption_8php_source.html#l00024">Encryption.php:24</a></div></div>
<div class="ttc" id="namespace_gravity_kit_1_1_gravity_view_1_1_foundation_1_1_encryption_html"><div class="ttname"><a href="namespace_gravity_kit_1_1_gravity_view_1_1_foundation_1_1_encryption.html">GravityKit\GravityView\Foundation\Encryption</a></div><div class="ttdoc">GPL-2.0-or-later </div><div class="ttdef"><b>Definition:</b> <a href="_encryption_8php_source.html#l00009">Encryption.php:9</a></div></div>
<div class="ttc" id="class_gravity_kit_1_1_gravity_view_1_1_foundation_1_1_encryption_1_1_encryption_html"><div class="ttname"><a href="class_gravity_kit_1_1_gravity_view_1_1_foundation_1_1_encryption_1_1_encryption.html">GravityKit\GravityView\Foundation\Encryption\Encryption</a></div><div class="ttdoc">This class provides basic data encryption functionality. </div><div class="ttdef"><b>Definition:</b> <a href="_encryption_8php_source.html#l00016">Encryption.php:16</a></div></div>
<div class="ttc" id="namespace_exception_html"><div class="ttname"><a href="namespace_exception.html">Exception</a></div></div>
<div class="ttc" id="class_gravity_kit_1_1_gravity_view_1_1_foundation_1_1_encryption_1_1_encryption_html_afd0a3e9021de0ca766baecac9988efc8"><div class="ttname"><a href="class_gravity_kit_1_1_gravity_view_1_1_foundation_1_1_encryption_1_1_encryption.html#afd0a3e9021de0ca766baecac9988efc8">GravityKit\GravityView\Foundation\Encryption\Encryption\get_instance</a></div><div class="ttdeci">static get_instance( $secret_key='')</div><div class="ttdoc">Returns class instance. </div><div class="ttdef"><b>Definition:</b> <a href="_encryption_8php_source.html#l00067">Encryption.php:67</a></div></div>
<div class="ttc" id="class_gravity_kit_1_1_gravity_view_1_1_foundation_1_1_encryption_1_1_encryption_html_a09cf31347f486a69d1a5311aec9cd49d"><div class="ttname"><a href="class_gravity_kit_1_1_gravity_view_1_1_foundation_1_1_encryption_1_1_encryption.html#a09cf31347f486a69d1a5311aec9cd49d">GravityKit\GravityView\Foundation\Encryption\Encryption\get_random_nonce</a></div><div class="ttdeci">get_random_nonce()</div><div class="ttdoc">Returns a random 24-byte nonce. </div><div class="ttdef"><b>Definition:</b> <a href="_encryption_8php_source.html#l00174">Encryption.php:174</a></div></div>
<div class="ttc" id="class_gravity_kit_1_1_gravity_view_1_1_foundation_1_1_encryption_1_1_encryption_html_a0dcac6065fa86fa59bfed5a17c3fed8e"><div class="ttname"><a href="class_gravity_kit_1_1_gravity_view_1_1_foundation_1_1_encryption_1_1_encryption.html#a0dcac6065fa86fa59bfed5a17c3fed8e">GravityKit\GravityView\Foundation\Encryption\Encryption\$_secret_key</a></div><div class="ttdeci">$_secret_key</div><div class="ttdef"><b>Definition:</b> <a href="_encryption_8php_source.html#l00031">Encryption.php:31</a></div></div>
<div class="ttc" id="class_gravity_kit_1_1_gravity_view_1_1_foundation_1_1_encryption_1_1_encryption_html_a6094445dc2f48d3e9cb94c2d80075a5d"><div class="ttname"><a href="class_gravity_kit_1_1_gravity_view_1_1_foundation_1_1_encryption_1_1_encryption.html#a6094445dc2f48d3e9cb94c2d80075a5d">GravityKit\GravityView\Foundation\Encryption\Encryption\encrypt</a></div><div class="ttdeci">encrypt( $data, $use_random_nonce=true, $custom_nonce=null)</div><div class="ttdoc">Encrypts data. </div><div class="ttdef"><b>Definition:</b> <a href="_encryption_8php_source.html#l00088">Encryption.php:88</a></div></div>
<div class="ttc" id="class_gravity_kit_1_1_gravity_view_1_1_foundation_1_1_encryption_1_1_encryption_html_a262c2478ac92061132e08deee82dd405"><div class="ttname"><a href="class_gravity_kit_1_1_gravity_view_1_1_foundation_1_1_encryption_1_1_encryption.html#a262c2478ac92061132e08deee82dd405">GravityKit\GravityView\Foundation\Encryption\Encryption\decrypt</a></div><div class="ttdeci">decrypt( $data)</div><div class="ttdoc">Decrypts data. </div><div class="ttdef"><b>Definition:</b> <a href="_encryption_8php_source.html#l00131">Encryption.php:131</a></div></div>
<div class="ttc" id="class_gravity_kit_1_1_gravity_view_1_1_foundation_1_1_encryption_1_1_encryption_html_a223259a5bedcd69a68d61f40326243e6"><div class="ttname"><a href="class_gravity_kit_1_1_gravity_view_1_1_foundation_1_1_encryption_1_1_encryption.html#a223259a5bedcd69a68d61f40326243e6">GravityKit\GravityView\Foundation\Encryption\Encryption\DEFAULT_NONCE</a></div><div class="ttdeci">const DEFAULT_NONCE</div><div class="ttdef"><b>Definition:</b> <a href="_encryption_8php_source.html#l00017">Encryption.php:17</a></div></div>
</div><!-- fragment --></div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/>
<script type="text/javascript">
jQuery( document ).ready( function( $ ) {
$( 'a.anchor[id^=_filters],a.anchor[id^=_actions]' ).each( function() {
$( this )
.text('#')
.attr( 'href', function() {
return '#' + $( this ).attr( 'id' );
}).prependTo( $( this ).parent('dt' ).next('dd') );
});
});
</script>
</body>
</html>