Skip to content

berry.encryption.AES128Encryption

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

The AES128Encryption class provides methods to encrypt and decrypt Stings using the famous AES 128bit encyption algorithm.

AES128Encryption::encrypt

Description

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

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

AES128Encryption::decrypt

Description

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

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

AES128Encryption Example

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

$encryptionKey = "%u#bmQjfhTws&(y%"; // 16-characters encryption key
$stringToEncrypt = "Hello World!";

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

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

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