Beispiel #1
0
 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;
 }
Beispiel #2
0
 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);
     }
     $plainText .= $this->getZeroPadding($plainText, $iv_size);
     $cipherText = openssl_encrypt($plainText, $this->method, $key, $this->openSSLOptions, $iv);
     $cipherText = $iv . $cipherText;
     return $cipherText;
 }
Beispiel #3
0
 /**
  * Encrypts a string using AES
  *
  * @param   string $stringToEncrypt The plaintext to encrypt
  * @param   bool   $base64encoded   Should I Base64-encode the result?
  *
  * @return   string  The cryptotext. Please note that the first 16 bytes of
  *                   the raw string is the IV (initialisation vector) which
  *                   is necessary for decoding the string.
  */
 public function encryptString($stringToEncrypt, $base64encoded = true)
 {
     $blockSize = $this->adapter->getBlockSize();
     $randVal = new Randval();
     $iv = $randVal->generate($blockSize);
     $key = $this->getExpandedKey($blockSize, $iv);
     $cipherText = $this->adapter->encrypt($stringToEncrypt, $key, $iv);
     // Optionally pass the result through Base64 encoding
     if ($base64encoded) {
         $cipherText = base64_encode($cipherText);
     }
     // Return the result
     return $cipherText;
 }