# bit-form/3.3.1/includes/Core/Cryptography/Cryptography.php

Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator &amp; Custom Form Builder, version 3.3.1. 50 lines.

- Page: https://pluginprobe.com/plugins/bit-form/3.3.1/code/includes/Core/Cryptography/Cryptography.php
- Raw: https://pluginprobe.com/plugins/bit-form/3.3.1/raw/includes/Core/Cryptography/Cryptography.php
- Modified: 2026-05-06T12:34:34+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/bit-form/3.3.1/code/includes/Core/Cryptography/Cryptography.php#L10-L20`.

```php
<?php

namespace BitCode\BitForm\Core\Cryptography;

use BitCode\BitForm\Core\Util\Log;
use WP_Error;

class Cryptography
{
  public static $sodiumCompat;

  public static function getSodiumCompat()
  {
    if (!self::$sodiumCompat) {
      self::$sodiumCompat = new SodiumCompat();
    }
    return self::$sodiumCompat;
  }

  public static function encrypt($message, $key)
  {
    try {
      if (32 !== strlen($key)) {
        $key = hash('sha256', $key, true); // Generate a 32-byte raw binary key
      }
      return base64_encode(self::getSodiumCompat()->compatEncrypt($message, $key));
    } catch (Exception $e) {
      // Handle the exception (e.g., log it, rethrow it, or return a meaningful error message)
      Log::debug_log('Encryption failed: ' . $e->getMessage());
      /* translators: %s: dynamic value. */
      return new WP_Error('encryption_failed', sprintf(__('Encryption failed: %s', 'bit-form'), esc_html($e->getMessage())));
    }
  }

  public static function decrypt($message, $key)
  {
    try {
      if (32 !== strlen($key)) {
        $key = hash('sha256', $key, true); // Generate a 32-byte raw binary key
      }
      return self::getSodiumCompat()->compatDecrypt(base64_decode($message), $key);
    } catch (\Exception $e) {
      // Handle the exception
      Log::debug_log('Decryption failed: ' . $e->getMessage());
      /* translators: %s: dynamic value. */
      return new WP_Error('decryption_failed', sprintf(__('Decryption failed: %s', 'bit-form'), esc_html($e->getMessage())));
    }
  }
}

```
