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

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

- Page: https://pluginprobe.com/plugins/bit-form/2.10.2/code/includes/Core/Cryptography/Cryptography.php
- Raw: https://pluginprobe.com/plugins/bit-form/2.10.2/raw/includes/Core/Cryptography/Cryptography.php
- Modified: 2024-03-10T10:26:12+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/2.10.2/code/includes/Core/Cryptography/Cryptography.php#L10-L20`.

```php
<?php

namespace BitCode\BitForm\Core\Cryptography;

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)
  {
    // check $key length and slice if key is longer than 32 bytes
    if (strlen($key) > 32) {
      $key = substr($key, 0, 32);
    }
    return base64_encode(self::getSodiumCompat()->compatEncrypt($message, $key));
  }

  public static function decrypt($message, $key)
  {
    if (strlen($key) > 32) {
      $key = substr($key, 0, 32);
    }
    return self::getSodiumCompat()->compatDecrypt(base64_decode($message), $key);
  }

}

```
