The crypt package creates a simple interface for the phpseclib AES-128 library. Its interface allows encryption and decryption of strings with a layer of base64 encoding for easy transmission including the initialization vector.
composer require crowdstar/crypt:~2.0.0Before using the library, you need to choose a secret key, which should be of size 16, 24 or 32 only.
<?php$secretKey = "1234567890123456";<?phpuseCrowdStar\Crypt\Crypt;
$encodedEncryptedData = (newCrypt($secretKey))->encrypt("message");<?phpuseCrowdStar\Crypt\Crypt;
$encodedEncryptedData = (newCrypt($secretKey))->decrypt("encoded_encrypted_data");<?phpuseCrowdStar\Crypt\Crypt;
$crypt = newCrypt($secretKey);
$alternateIVLength = 8;
$encodedEncryptedData = $crypt->encrypt("message", $alternateIVLength);
$plainText = $crypt->decrypt($encodedEncryptedData, $alternateIVLength);When bad data is passed in, the return value of method call CrowdStar\Crypt\Crypt::decrypt() will be an empty string.