PluginProbe
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder / 4.3.6
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder v4.3.6
6.2.14 6.2.13 6.2.12 6.2.10 6.2.11 6.2.9 6.2.8 6.2.7 6.2.6 6.2.5 6.2.4 6.2.3 6.2.2 3.6.22 3.6.31 3.6.40 3.6.41 3.6.42 3.6.50 3.6.51 3.6.60 3.6.61 3.6.62 3.6.64 3.6.65 All 196 releases
fluentform / app / Helpers / Protector.php

Protector.php in Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder 4.3.6, at app/Helpers/Protector.php

74 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentForm\App\Helpers;
4
5 class Protector
6 {
7 /**
8 * Get the salt for the encryption and decryption.
9 */
10 public static function getSalt()
11 {
12 $salt = get_option('_fluentform_security_salt');
13
14 if (!$salt) {
15 $salt = wp_generate_password();
16
17 update_option('_fluentform_security_salt', $salt, 'no');
18 }
19
20 return $salt;
21 }
22
23 /**
24 * Encryp a text using a predefined salt.
25 *
26 * @param string $text
27 * @return string $text
28 */
29 public static function encrypt($text)
30 {
31 $key = static::getSalt();
32
33 $ivlen = openssl_cipher_iv_length($cipher = "AES-128-CBC");
34
35 $iv = openssl_random_pseudo_bytes($ivlen);
36
37 $ciphertext_raw = openssl_encrypt($text, $cipher, $key, $options = OPENSSL_RAW_DATA, $iv);
38
39 $hmac = hash_hmac('sha256', $ciphertext_raw, $key, $as_binary = true);
40
41 return base64_encode($iv . $hmac . $ciphertext_raw);
42 }
43
44 /**
45 * Decrypt a text using a predefined salt.
46 *
47 * @param string $text
48 * @return string $text
49 */
50 public static function decrypt($text)
51 {
52 $key = static::getSalt();
53
54 $c = base64_decode($text);
55
56 $ivlen = openssl_cipher_iv_length($cipher = "AES-128-CBC");
57
58 $iv = substr($c, 0, $ivlen);
59
60 $hmac = substr($c, $ivlen, $sha2len = 32);
61
62 $ciphertext_raw = substr($c, $ivlen + $sha2len);
63
64 $original_plaintext = openssl_decrypt($ciphertext_raw, $cipher, $key, $options = OPENSSL_RAW_DATA, $iv);
65
66 $calcmac = hash_hmac('sha256', $ciphertext_raw, $key, $as_binary = true);
67
68 if (hash_equals($hmac, $calcmac)) // timing attack safe comparison
69 {
70 return $original_plaintext;
71 }
72 }
73 }
74