PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / 3.1.0
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder v3.1.0
V-3.3.0 3.2.2 3.2.1 3.2.0 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 V3.0.3 V3.0.2 -3.0.1 V_3.0.0 1.1.1 1.1.8 1.2 1.3 1.4 1.4.18 1.5.2 1.9 2.0 2.10.0 2.10.1 2.10.2 All 137 releases
bit-form / includes / Core / Cryptography / Cryptography.php

Cryptography.php in Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder 3.1.0, at includes/Core/Cryptography/Cryptography.php

50 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace BitCode\BitForm\Core\Cryptography;
4
5 use BitCode\BitForm\Core\Util\Log;
6 use WP_Error;
7
8 class Cryptography
9 {
10 public static $sodiumCompat;
11
12 public static function getSodiumCompat()
13 {
14 if (!self::$sodiumCompat) {
15 self::$sodiumCompat = new SodiumCompat();
16 }
17 return self::$sodiumCompat;
18 }
19
20 public static function encrypt($message, $key)
21 {
22 try {
23 if (32 !== strlen($key)) {
24 $key = hash('sha256', $key, true); // Generate a 32-byte raw binary key
25 }
26 return base64_encode(self::getSodiumCompat()->compatEncrypt($message, $key));
27 } catch (Exception $e) {
28 // Handle the exception (e.g., log it, rethrow it, or return a meaningful error message)
29 Log::debug_log('Encryption failed: ' . $e->getMessage());
30 /* translators: %s: dynamic value. */
31 return new WP_Error('encryption_failed', sprintf(__('Encryption failed: %s', 'bit-form'), esc_html($e->getMessage())));
32 }
33 }
34
35 public static function decrypt($message, $key)
36 {
37 try {
38 if (32 !== strlen($key)) {
39 $key = hash('sha256', $key, true); // Generate a 32-byte raw binary key
40 }
41 return self::getSodiumCompat()->compatDecrypt(base64_decode($message), $key);
42 } catch (\Exception $e) {
43 // Handle the exception
44 Log::debug_log('Decryption failed: ' . $e->getMessage());
45 /* translators: %s: dynamic value. */
46 return new WP_Error('decryption_failed', sprintf(__('Decryption failed: %s', 'bit-form'), esc_html($e->getMessage())));
47 }
48 }
49 }
50