Skip to content

berry.encryption.AES256Encryption

Nikos Siatras edited this page Oct 2, 2022 · 13 revisions

The AES256Encryption class provides methods to encrypt and decrypt Stings using the famous AES 256bit encryption algorithm.

AES256Encryption::encrypt

Description

static function encrypt(string $key, string $data): string

Encrypts a string using AES Cipher (CBC) with an 32bytes key

AES256Encryption::decrypt

Description

static function decrypt(string $key, string $data): string

Decrypts string data using AES Cipher (CBC) with 32bytes key

AES256Encryption Example

require_once(__DIR__ . "/berry/encryption.php"); // Include berry encryption package

$encryptionKey = "%2IR5wdW%Q7bLE*v+v4WpNfM*pkeM4sz"; // 32-characters encryption key
$stringToEncrypt = "This is a simple text we need to encrypt";

print "Original String: " . $stringToEncrypt."<br>";

$encryptedString = AES256Encryption::encrypt($encryptionKey,$stringToEncrypt);
print "Encrypted String: " . $encryptedString."<br>";

$descryptedString = AES256Encryption::decrypt($encryptionKey, $encryptedString);
print "Decrypted String: " . $descryptedString."<br>";