Example #1
0
function encryptCookie($value)
{
    // serialize array values
    if (!$value) {
        return false;
    }
    if (is_array($value)) {
        $value = serialize($value);
    }
    // generate an SHA-256 HMAC hash where data = session ID and key = defined constant
    $key = hash_hmac('sha256', session_id(), ENCRYPTION_KEY_HMAC);
    if (strlen($key) > 24) {
        $key = substr($key, 0, 24);
    }
    // generate random value for IV
    $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_CBC);
    $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
    // encrypt the data with the key and IV using AES-256
    $crypttext = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $value, MCRYPT_MODE_CBC, $iv);
    // generate an SHA-256 HMAC hash where data = encrypted text and key = defined constant
    $signature = hash_hmac('sha256', $crypttext, SIG_HMAC);
    $cookiedough = array();
    $cookiedough['sig'] = $signature;
    $cookiedough['iv'] = $iv;
    $cookiedough['text'] = $crypttext;
    $final = serialize($cookiedough);
    return base64_encode($final);
    //encode for cookie
}
Example #2
0
function encrypt($pure_string, $encryption_key)
{
    $iv_size = mcrypt_get_iv_size(MCRYPT_BLOWFISH, MCRYPT_MODE_ECB);
    $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
    $encrypted_string = mcrypt_encrypt(MCRYPT_BLOWFISH, $encryption_key, utf8_encode($pure_string), MCRYPT_MODE_ECB, $iv);
    return base64_encode($encrypted_string);
}
/** Authenticate Session
 *
 * Checks if user is logging in, logging out, or session expired and performs
 * actions accordingly
 *
 * @return null
 */
function authenticate_local()
{
    global $iface_expire;
    global $session_key;
    global $ldap_use;
    if (isset($_SESSION['userid']) && isset($_SERVER["QUERY_STRING"]) && $_SERVER["QUERY_STRING"] == "logout") {
        logout(_('You have logged out.'), 'success');
    }
    // If a user had just entered his/her login && password, store them in our session.
    if (isset($_POST["authenticate"])) {
        $_SESSION["userpwd"] = base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, md5($session_key), $_POST['password'], MCRYPT_MODE_CBC, md5(md5($session_key))));
        $_SESSION["userlogin"] = $_POST["username"];
        $_SESSION["userlang"] = $_POST["userlang"];
    }
    // Check if the session hasnt expired yet.
    if (isset($_SESSION["userid"]) && $_SESSION["lastmod"] != "" && time() - $_SESSION["lastmod"] > $iface_expire) {
        logout(_('Session expired, please login again.'), 'error');
    }
    // If the session hasn't expired yet, give our session a fresh new timestamp.
    $_SESSION["lastmod"] = time();
    if ($ldap_use && userUsesLDAP()) {
        LDAPAuthenticate();
    } else {
        SQLAuthenticate();
    }
}
Example #4
0
 public static function EncryptString($key, $iv, $enc)
 {
     if (is_null($key) || is_null($iv) || is_null($enc)) {
         return $enc;
     }
     return mcrypt_encrypt(CRYPTO_METHOD, $key, base64_encode($enc), CRYPTO_MODE, $iv);
 }
 private static function _encrypt($value, $key)
 {
     $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
     $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
     $crypttext = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $value, MCRYPT_MODE_ECB, $iv);
     return trim(base64_encode($crypttext));
 }
Example #6
0
function checkRegisterParams()
{
    // Create DB connection
    require_once __ROOT__ . '/admin/include/DBclass.php';
    $sqlConn = new DBclass();
    // Check for the submit data
    $email = $sqlConn->realEscapeString(filter_input(INPUT_POST, 'email', FILTER_DEFAULT));
    $firstname = $sqlConn->realEscapeString(filter_input(INPUT_POST, 'firstname', FILTER_DEFAULT));
    $lastname = $sqlConn->realEscapeString(filter_input(INPUT_POST, 'lastname', FILTER_DEFAULT));
    $password = $sqlConn->realEscapeString(filter_input(INPUT_POST, 'password', FILTER_DEFAULT));
    $passwordRe = $sqlConn->realEscapeString(filter_input(INPUT_POST, 'passwordRe', FILTER_DEFAULT));
    $address = $sqlConn->realEscapeString(filter_input(INPUT_POST, 'address', FILTER_DEFAULT));
    $postnumber = $sqlConn->realEscapeString(filter_input(INPUT_POST, 'postnumber', FILTER_DEFAULT));
    $city = $sqlConn->realEscapeString(filter_input(INPUT_POST, 'city', FILTER_DEFAULT));
    $phone = $sqlConn->realEscapeString(filter_input(INPUT_POST, 'phone', FILTER_DEFAULT));
    // Check inputs validity
    // Encrypt password
    $passwordEncypt = base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, md5($email), $password, MCRYPT_MODE_CBC, md5(md5($email))));
    // Record current date and time
    $timeAndDate = date("Y-m-d h:i:sa");
    // Insert:
    $query = "INSERT INTO user (firstname, lastname, password, address,\n            email, phone, city, postnumber, usertype_idusertype, timeAndDate) \n            VALUES ('" . $firstname . "','" . $lastname . "','" . $passwordEncypt . "','" . $address . "','" . $email . "','" . $phone . "','" . $city . "'," . $postnumber . ",1,'" . $timeAndDate . "')";
    echo "<br/>" . $query . "<br/>";
    $sqlConn->exeQuery($query);
    // Remove DB connection
    unset($sqlConn);
}
Example #7
0
 /**
  * @param string $plain
  * @return string garble
  */
 public function encrypt($plain)
 {
     $iv = mcrypt_create_iv($this->ivSize, MCRYPT_DEV_URANDOM);
     $crypt = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $this->key, $plain, MCRYPT_MODE_CBC, $iv);
     $garble = base64_encode($iv . $crypt);
     return $garble;
 }
function do_encrypt($data)
{
    $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_CBC);
    $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
    $encrypt = getEncryptionKey(32);
    return base64_encode($iv . mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $encrypt, $data, MCRYPT_MODE_CBC, $iv));
}
Example #9
0
function encrypt($data, $key, $iv)
{
    $blocksize = 16;
    $pad = $blocksize - strlen($data) % $blocksize;
    $data = $data . str_repeat(chr($pad), $pad);
    return bin2hex(mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $data, MCRYPT_MODE_CBC, $iv));
}
Example #10
0
 /**
  *
  * Encrypt a string (Passwords)
  *
  * @param string $string value to encrypt
  *
  * @return string encrypted string
  */
 public static function encrypt($string)
 {
     if (empty($string)) {
         return $string;
     }
     //only encrypt if needed
     if (strpos($string, '$BackWPup$ENC1$') !== FALSE || strpos($string, '$BackWPup$RIJNDAEL$') !== FALSE) {
         if (strpos($string, '$BackWPup$ENC1$O$') !== FALSE && strpos($string, '$BackWPup$RIJNDAEL$O$') !== FALSE && defined('BACKWPUP_ENC_KEY') && BACKWPUP_ENC_KEY) {
             $string = self::decrypt($string);
         } else {
             return $string;
         }
     }
     if (defined('BACKWPUP_ENC_KEY') && BACKWPUP_ENC_KEY) {
         $key = BACKWPUP_ENC_KEY;
         $key_type = 'O$';
     } else {
         $key = DB_NAME . DB_USER . DB_PASSWORD;
         $key_type = '';
     }
     $key = md5($key);
     if (!function_exists('mcrypt_encrypt')) {
         $result = '';
         for ($i = 0; $i < strlen($string); $i++) {
             $char = substr($string, $i, 1);
             $keychar = substr($key, $i % strlen($key) - 1, 1);
             $char = chr(ord($char) + ord($keychar));
             $result .= $char;
         }
         return '$BackWPup$ENC1$' . $key_type . base64_encode($result);
     }
     return '$BackWPup$RIJNDAEL$' . $key_type . base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, md5($key), trim($string), MCRYPT_MODE_CBC, md5(md5($key))));
 }
Example #11
0
 public static function encrypt($text, $key = '')
 {
     if (!$text) {
         return '';
     }
     return @bin2hex(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $text, MCRYPT_MODE_ECB));
 }
Example #12
0
 public function encryptString($plaintext, $key)
 {
     srand((double) microtime() * 1000000);
     $iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_BLOWFISH, MCRYPT_MODE_CFB), MCRYPT_RAND);
     $cipher = mcrypt_encrypt(MCRYPT_BLOWFISH, $key, $plaintext, MCRYPT_MODE_CFB, $iv);
     return $iv . $cipher;
 }
Example #13
0
 public function encryptedSerialize($object)
 {
     $serializedString = $this->serialize($object);
     $encryptedString = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $this->key, $serializedString, MCRYPT_MODE_CBC, $this->initVector);
     $encryptedString = $this->initVector . $encryptedString;
     return base64_encode($encryptedString);
 }
Example #14
0
function a2b_encrypt($text, $key)
{
    $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
    $iv = mcrypt_create_iv($iv_size);
    $temp = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, md5($key), $text, MCRYPT_MODE_ECB, $iv);
    return $temp;
}
Example #15
0
	protected function ecryptdString($str,$keys="6461772803150152",$iv="8105547186756005",$cipher_alg=MCRYPT_RIJNDAEL_128){
		//
		//
		//source_id=xxx&target_id=xxx&type=1
		$encrypted_string = bin2hex(mcrypt_encrypt($cipher_alg, $keys, $str, MCRYPT_MODE_CBC,$iv));
		return $encrypted_string;
	}
Example #16
0
 public function encrypt($string, $cryptoKey = '')
 {
     $cryptoKey = $cryptoKey ? $cryptoKey : $this->cryptoKey;
     list($key, $iv) = $this->splitKeyIv($cryptoKey);
     $string = $this->pkcs5Padding($string, $this->blockSize);
     return base64_encode(mcrypt_encrypt($this->cryptoAlgo, $key, $string, $this->cipherMode, $iv));
 }
Example #17
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)
 {
     // Calculate the key to use for encryption
     $keySize = mcrypt_get_key_size($this->_cipherType, $this->_cipherMode);
     if (strlen($this->_keyString) != 32) {
         $key = hash('sha256', $this->_keyString, true);
     } else {
         $key = $this->_keyString;
     }
     // Set up the IV (Initialization Vector)
     $iv_size = mcrypt_get_iv_size($this->_cipherType, $this->_cipherMode);
     $iv = mcrypt_create_iv($iv_size, MCRYPT_DEV_URANDOM);
     if (empty($iv)) {
         $iv = mcrypt_create_iv($iv_size, MCRYPT_DEV_RANDOM);
     }
     if (empty($iv)) {
         $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
     }
     // Encrypt the data
     $cipherText = mcrypt_encrypt($this->_cipherType, $key, $stringToEncrypt, $this->_cipherMode, $iv);
     // Prepend the IV to the ciphertext
     $cipherText = $iv . $cipherText;
     // Optionally pass the result through Base64 encoding
     if ($base64encoded) {
         $cipherText = base64_encode($cipherText);
     }
     // Return the result
     return $cipherText;
 }
Example #18
0
 protected function sendJsonRequest($method, $data, $encrypted = false, $ssl = false)
 {
     $protocol = !$ssl ? 'http:' : 'https:';
     $url_params = $this->_current_params + array('method' => $method);
     $url = $protocol . $this->_json_endpoint . '?' . http_build_query($url_params);
     $json_data = json_encode($data);
     $this->last_request_data = $json_data;
     if ($encrypted) {
         $json_data = bin2hex(mcrypt_encrypt(MCRYPT_BLOWFISH, $this->_encryption_cipher, $json_data, MCRYPT_MODE_ECB));
     }
     $curl = curl_init();
     curl_setopt($curl, CURLOPT_URL, $url);
     curl_setopt($curl, CURLOPT_POST, 1);
     curl_setopt($curl, CURLOPT_POSTFIELDS, $json_data);
     curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
     curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: text/plain'));
     $json_response = curl_exec($curl);
     $this->last_response_data = $json_response;
     $response = json_decode($json_response, true);
     if (!isset($response['stat']) || $response['stat'] != 'ok') {
         $this->last_error = $response['message'] . ' (' . $this->defineErrorCode($response['code']) . ')';
         return false;
     }
     if (isset($response['result']['syncTime'])) {
         $this->_last_synctime = $this->decryptSyncTime($response['result']['syncTime']);
     }
     return $response['result'];
 }
Example #19
0
 function enc_str($str, $key = '1234567890!')
 {
     $iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC), MCRYPT_DEV_URANDOM);
     $encrypted = base64_encode($iv . mcrypt_encrypt(MCRYPT_RIJNDAEL_128, hash('sha256', $key, true), $str, MCRYPT_MODE_CBC, $iv));
     echo "ENCRYPT> {$str} -> \${$encrypted}\n";
     return $encrypted;
 }
Example #20
0
 /**
  * Encrypt a string using Mcrypt.
  *
  * The string will be encrypted using the AES-256 scheme and will be base64 encoded.
  *
  * @param  string  $value
  * @return string
  */
 public static function encrypt($value)
 {
     $iv = mcrypt_create_iv(static::iv_size(), static::randomizer());
     $value = static::pad($value);
     $value = mcrypt_encrypt(static::$cipher, static::key(), $value, static::$mode, $iv);
     return base64_encode($iv . $value);
 }
Example #21
0
 public function sendRequest($request_params)
 {
     //encrypt the request parameters
     $enc_request = base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $this->_app_key, json_encode($request_params), MCRYPT_MODE_ECB));
     //create the params array, which will
     //be the POST parameters
     $params = array();
     $params['enc_request'] = $enc_request;
     $params['app_id'] = $this->_app_id;
     //initialize and setup the curl handler
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, $this->_api_url);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($ch, CURLOPT_POST, count($params));
     curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
     //execute the request
     $result = curl_exec($ch);
     //json_decode the result
     $result = @json_decode($result, true);
     //check if we're able to json_decode the result correctly
     if ($result == false || isset($result['success']) == false) {
         throw new Exception('Request was not correct');
     }
     //if there was an error in the request, throw an exception
     if ($result['success'] == false) {
         throw new Exception($result['errormsg']);
     }
     //if everything went great, return the data
     if ($this->_api_resp == "json") {
         return json_encode($result['data']);
     } else {
         return $result['data'];
     }
 }
Example #22
0
 /**
  * Encrypt a string.
  *
  * @param string $str String to encrypt.
  *
  * @return string
  */
 public function encrypt($str)
 {
     $iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC), MCRYPT_RAND);
     $str = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $this->key, $str, MCRYPT_MODE_CBC, $iv);
     $str = $iv . $str;
     return base64_encode($str);
 }
Example #23
0
 public function encrypt_string($input, $key)
 {
     $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC);
     $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
     $cipher = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $input, MCRYPT_MODE_CBC, $iv);
     return base64_encode($iv . $cipher);
 }
Example #24
0
 /**
  * @param $strIn
  * @param $strEncryptionPassword
  * @return string
  */
 public static function encryptAndEncode($strIn, $strEncryptionPassword)
 {
     $strIV = $strEncryptionPassword;
     $strIn = self::addPKCS5Padding($strIn);
     $strCrypt = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $strEncryptionPassword, $strIn, MCRYPT_MODE_CBC, $strIV);
     return "@" . bin2hex($strCrypt);
 }
Example #25
0
function b1n_crypt($str)
{
    require b1n_SECRETKEY_FILE;
    $iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB), MCRYPT_RAND);
    $str = base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $str, MCRYPT_MODE_ECB, $iv));
    return $str;
}
Example #26
0
 /**
  * @param string $data
  * @param string $secretKey
  * @return string
  */
 public function encrypt($data, $secretKey)
 {
     $this->_validateKey($secretKey);
     $encrypted = base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $secretKey, $data, MCRYPT_MODE_ECB));
     return strtr($encrypted, '+=/', '-_.');
     // substitute URI reserved characters
 }
 public static function encode($encrypt, $key)
 {
     $iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_DES, MCRYPT_MODE_ECB), MCRYPT_RAND);
     $passcrypt = mcrypt_encrypt(MCRYPT_DES, $key, $encrypt, MCRYPT_MODE_ECB, $iv);
     $encode = base64_encode($passcrypt);
     return $encode;
 }
Example #28
0
 public function encrypt($str, $key)
 {
     $block = mcrypt_get_block_size('des', 'ecb');
     $pad = $block - strlen($str) % $block;
     $str .= str_repeat(chr($pad), $pad);
     return base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $str, MCRYPT_MODE_ECB));
 }
 public function beforeSave()
 {
     $encryptionMethod = "AES-256-CBC";
     //$this->data['MorphChartProblem']['name'] = openssl_encrypt($this->data['MorphChartProblem']['name'], $encryptionMethod, $this->getEncryptionKey(), false, "8werjsdfj00932sd");
     $this->data['MorphChartProblem']['name'] = trim(base64_encode(mcrypt_encrypt(MCRYPT_3DES, substr($this->getEncryptionKey(), 0, 24), $this->data['MorphChartProblem']['name'], MCRYPT_MODE_CBC, "8werjsdf")));
     return true;
 }
Example #30
0
 function encrypt($string, $salt = ENCRYPT_PASSWORD_SALT)
 {
     # Generates encrypted string
     $encrypted = base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, md5($salt), $string, MCRYPT_MODE_CBC, md5(md5($salt))));
     #gives back the string
     return $encrypted;
 }