Back to Aes class

Method decryptString

public string
decryptString
(mixed $stringToDecrypt, mixed $base64encoded = true)
Decrypts a ciphertext into a plaintext string using AES
Parameters
  • string $stringToDecrypt The ciphertext to decrypt. The first 16 bytes of the raw string must contain the IV (initialisation vector).
  • bool $base64encoded Should I Base64-decode the data before decryption?
Returns
  • string The plain text string
Class: Aes
Project: Joomla

Method decryptString - Source code

/**
 * Decrypts a ciphertext into a plaintext string using AES
 *
 * @param   string $stringToDecrypt The ciphertext to decrypt. The first 16 bytes of the raw string must contain
 *                                  the IV (initialisation vector).
 * @param   bool   $base64encoded   Should I Base64-decode the data before decryption?
 *
 * @return   string  The plain text string
 */
public function decryptString($stringToDecrypt, $base64encoded = true)
{
    if ($base64encoded) {
        $stringToDecrypt = base64_decode($stringToDecrypt);
    }
    // Extract IV
    $iv_size = $this->adapter->getBlockSize();
    $iv = substr($stringToDecrypt, 0, $iv_size);
    $key = $this->getExpandedKey($iv_size, $iv);
    // Decrypt the data
    $plainText = $this->adapter->decrypt($stringToDecrypt, $key);
    return $plainText;
}