Back to Mcrypt class

Method encrypt

public string
encrypt
(mixed $plainText, mixed $key, mixed $iv = null)
Encrypt the data
Parameters
  • string $plainText Plaintext data
  • string $key Encryption key
  • string $iv IV for the encryption
Returns
  • string Encrypted data
Class: Mcrypt
Project: Joomla

Method encrypt - Source code

/**
 * Encrypt the data
 *
 * @param   string  $plainText  Plaintext data
 * @param   string  $key        Encryption key
 * @param   string  $iv         IV for the encryption
 *
 * @return   string  Encrypted data
 */
public function encrypt($plainText, $key, $iv = null)
{
    $iv_size = $this->getBlockSize();
    $key = $this->resizeKey($key, $iv_size);
    $iv = $this->resizeKey($iv, $iv_size);
    if (empty($iv)) {
        $randVal = new Randval();
        $iv = $randVal->generate($iv_size);
    }
    $cipherText = mcrypt_encrypt($this->cipherType, $key, $plainText, $this->cipherMode, $iv);
    $cipherText = $iv . $cipherText;
    return $cipherText;
}