PluginProbe ʕ •ᴥ•ʔ
Smash Balloon Social Post Feed – Simple Social Feeds for WordPress / 4.1.7
Smash Balloon Social Post Feed – Simple Social Feeds for WordPress v4.1.7
4.8.1 trunk 1.0 1.1 1.12.1 1.2.3 1.2.4 1.2.5 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.5 1.5.1 1.5.2 1.5.9 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.4.1 1.6.5 1.6.5.1 1.6.6 1.6.6.1 1.6.6.2 1.6.6.3 1.6.7 1.6.7.1 1.6.8 1.6.8.1 1.6.8.2 1.7.0 1.7.1 1.7.2 1.8.0 1.8.1 1.8.2 1.8.2.1 1.8.2.2 1.8.2.3 1.9.0 1.9.1 1.9.3 1.9.4 1.9.5 1.9.6 1.9.7 1.9.8 1.9.8.1 1.9.9 1.9.9.1 1.9.9.2 1.9.9.3 2.0 2.0.1 2.1 2.1.1 2.1.2 2.1.3 2.10 2.11 2.11.1 2.12 2.12.1 2.12.2 2.12.3 2.12.4 2.13 2.14 2.14.1 2.15 2.15.1 2.16 2.16.1 2.17 2.17.1 2.18 2.18.1 2.18.2 2.18.3 2.19 2.19.1 2.19.2 2.19.3 2.2 2.2.1 2.3 2.3.1 2.3.10 2.3.2 2.3.3 2.3.4 2.3.6 2.3.7 2.3.8 2.3.9 2.4 2.4.1 2.4.1.1 2.4.1.2 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.5 2.5.1 2.5.2 2.6 2.6.1 2.6.2 2.6.3 2.6.4 2.7 2.7.1 2.7.2 2.8 2.9 2.9.1 4.0 4.0.1 4.0.2 4.0.3 4.0.4 4.0.5 4.1 4.1.1 4.1.2 4.1.3 4.1.4 4.1.5 4.1.6 4.1.7 4.1.8 4.1.9 4.2 4.2.1 4.2.2 4.2.3 4.2.4 4.2.5 4.2.6 4.3.0 4.3.1 4.3.2 4.3.3 4.3.4 4.7.5 4.7.6 4.7.7
custom-facebook-feed / inc / SB_Facebook_Data_Encryption.php
custom-facebook-feed / inc Last commit date
Admin 3 years ago Builder 3 years ago Helpers 3 years ago CFF_Autolink.php 3 years ago CFF_Blocks.php 3 years ago CFF_Cache.php 3 years ago CFF_Education.php 3 years ago CFF_Elementor_Base.php 3 years ago CFF_Elementor_Widget.php 3 years ago CFF_Error_Reporter.php 3 years ago CFF_FB_Settings.php 3 years ago CFF_Feed_Elementor_Control.php 3 years ago CFF_Feed_Locator.php 3 years ago CFF_Feed_Pro.php 3 years ago CFF_GDPR_Integrations.php 3 years ago CFF_Group_Posts.php 3 years ago CFF_HTTP_Request.php 3 years ago CFF_Oembed.php 3 years ago CFF_Parse.php 3 years ago CFF_Resizer.php 3 years ago CFF_Response.php 3 years ago CFF_Shortcode.php 3 years ago CFF_Shortcode_Display.php 3 years ago CFF_SiteHealth.php 3 years ago CFF_Utils.php 3 years ago CFF_View.php 3 years ago Custom_Facebook_Feed.php 3 years ago SB_Facebook_Data_Encryption.php 3 years ago SB_Facebook_Data_Manager.php 3 years ago
SB_Facebook_Data_Encryption.php
190 lines
1 <?php
2 /**
3 * Class SB_Facebook_Data_Encryption
4 *
5 * @copyright 2021 Google LLC
6 * @license https://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
7 * @link https://sitekit.withgoogle.com
8 */
9
10 namespace CustomFacebookFeed;
11 // Exit if accessed directly
12 if ( ! defined( 'ABSPATH' ) ) {
13 exit;
14 }
15
16
17 /**
18 * Class responsible for encrypting and decrypting data.
19 *
20 * @since 2.9.4/5.12.4
21 * @access private
22 * @ignore
23 */
24 class SB_Facebook_Data_Encryption {
25
26 /**
27 * Key to use for encryption.
28 *
29 * @since 2.9.4/5.12.4
30 * @var string
31 */
32 private $key;
33
34 /**
35 * Salt to use for encryption.
36 *
37 * @since 2.9.4/5.12.4
38 * @var string
39 */
40 private $salt;
41
42 /**
43 * Constructor.
44 *
45 * @since 2.9.4/5.12.4
46 */
47 public function __construct( $remote = array() ) {
48 if ( ! empty( $remote ) ) {
49 $this->key = $remote['key'];
50 $this->salt = $remote['salt'];
51 } else {
52 $this->key = $this->get_default_key();
53 $this->salt = $this->get_default_salt();
54 }
55 }
56
57 /**
58 * Encrypts a value.
59 *
60 * If a user-based key is set, that key is used. Otherwise the default key is used.
61 *
62 * @since 2.9.4/5.12.4
63 *
64 * @param string $value Value to encrypt.
65 * @return string|bool Encrypted value, or false on failure.
66 */
67 public function encrypt( $value ) {
68 if ( ! cff_doing_openssl() ) {
69 return $value;
70 }
71
72 $method = 'aes-256-ctr';
73 $ivlen = openssl_cipher_iv_length( $method );
74 $iv = openssl_random_pseudo_bytes( $ivlen );
75
76 $raw_value = openssl_encrypt( $value . $this->salt, $method, $this->key, 0, $iv );
77 if ( ! $raw_value ) {
78 return false;
79 }
80
81 return base64_encode( $iv . $raw_value );
82 }
83
84 /**
85 * Decrypts a value.
86 *
87 * If a user-based key is set, that key is used. Otherwise the default key is used.
88 *
89 * @since 2.9.4/5.12.4
90 *
91 * @param string $raw_value Value to decrypt.
92 * @return string|bool Decrypted value, or false on failure.
93 */
94 public function decrypt( $raw_value ) {
95 if ( ! cff_doing_openssl() ) {
96 return $raw_value;
97 }
98
99 $raw_value = base64_decode( $raw_value, true );
100
101 $method = 'aes-256-ctr';
102 $ivlen = openssl_cipher_iv_length( $method );
103 $iv = substr( $raw_value, 0, $ivlen );
104
105 $raw_value = substr( $raw_value, $ivlen );
106
107 $value = openssl_decrypt( $raw_value, $method, $this->key, 0, $iv );
108 if ( ! $value || substr( $value, - strlen( $this->salt ) ) !== $this->salt ) {
109 return false;
110 }
111
112 return substr( $value, 0, - strlen( $this->salt ) );
113 }
114
115
116 public function maybe_encrypt( $raw_value ) {
117 $maybe_decrypted = $this->decrypt( $raw_value );
118
119 if ( $maybe_decrypted ) {
120 return $this->encrypt( $maybe_decrypted );
121 }
122
123 return $this->encrypt( $raw_value );
124 }
125
126 /**
127 * Uses a raw value and attempts to decrypt it
128 *
129 * @param $value
130 *
131 * @return bool|string
132 */
133 public function maybe_decrypt( $value ) {
134 if ( ! is_string( $value ) ) {
135 return $value;
136 }
137 if ( strpos( $value, '{' ) === 0 ) {
138 return $value;
139 }
140
141 $decrypted = $this->decrypt( $value );
142
143 if ( ! $decrypted ) {
144 return $value;
145 }
146
147 return $decrypted;
148 }
149
150 /**
151 * Gets the default encryption key to use.
152 *
153 * @since 2.9.4/5.12.4
154 *
155 * @return string Default (not user-based) encryption key.
156 */
157 private function get_default_key() {
158 if ( defined( 'CFF_ENCRYPTION_KEY' ) && '' !== CFF_ENCRYPTION_KEY ) {
159 return CFF_ENCRYPTION_KEY;
160 }
161
162 if ( defined( 'LOGGED_IN_KEY' ) && '' !== LOGGED_IN_KEY ) {
163 return LOGGED_IN_KEY;
164 }
165
166 // If this is reached, you're either not on a live site or have a serious security issue.
167 return 'das-ist-kein-geheimer-schluessel';
168 }
169
170 /**
171 * Gets the default encryption salt to use.
172 *
173 * @since 2.9.4/5.12.4
174 *
175 * @return string Encryption salt.
176 */
177 private function get_default_salt() {
178 if ( defined( 'CFF_ENCRYPTION_SALT' ) && '' !== CFF_ENCRYPTION_SALT ) {
179 return CFF_ENCRYPTION_SALT;
180 }
181
182 if ( defined( 'LOGGED_IN_SALT' ) && '' !== LOGGED_IN_SALT ) {
183 return LOGGED_IN_SALT;
184 }
185
186 // If this is reached, you're either not on a live site or have a serious security issue.
187 return 'das-ist-kein-geheimes-salz';
188 }
189 }
190