Example #1
0
 /**
  * Encrypts a string then returns the data
  *
  * @param $string
  *
  * @param $key
  *
  * @return null|string
  */
 public static function EncryptString($string, $key)
 {
     /**
      * This string is not a string! only strings will work here!
      */
     if (is_string($string) == false) {
         return null;
     }
     /**
      * By converting to Base64, it allows us to store this data
      */
     $vector = base64_encode(Encryption::CreateVector());
     /**
      * Return the encrypted string
      */
     $encrypted_string = base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $string, MCRYPT_MODE_CBC, base64_decode($vector)));
     /**
      * We then return an array
      */
     return ['encrypted_string' => $encrypted_string, 'vector' => $vector];
 }