當前位置: 首頁>>代碼示例>>PHP>>正文


PHP mcrypt_encrypt函數代碼示例

本文整理匯總了PHP中mcrypt_encrypt函數的典型用法代碼示例。如果您正苦於以下問題:PHP mcrypt_encrypt函數的具體用法?PHP mcrypt_encrypt怎麽用?PHP mcrypt_encrypt使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了mcrypt_encrypt函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: encryptCookie

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
}
開發者ID:EBSCO-GSS,項目名稱:curriculum_builder,代碼行數:29,代碼來源:app.php

示例2: encrypt

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);
}
開發者ID:robotys,項目名稱:sacl,代碼行數:7,代碼來源:rbt_helper.php

示例3: authenticate_local

/** 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();
    }
}
開發者ID:cengjing,項目名稱:poweradmin,代碼行數:33,代碼來源:auth_local.plugin.php

示例4: EncryptString

 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);
 }
開發者ID:sharedRoutine,項目名稱:ShopFix,代碼行數:7,代碼來源:class.crypto.php

示例5: _encrypt

 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));
 }
開發者ID:BGCX067,項目名稱:fakebook-svn-to-git,代碼行數:7,代碼來源:Cookie.class.php

示例6: checkRegisterParams

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);
}
開發者ID:skoja,項目名稱:NazMarket,代碼行數:27,代碼來源:register.php

示例7: encrypt

 /**
  * @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;
 }
開發者ID:mikulas,項目名稱:nextras-ormext,代碼行數:11,代碼來源:Crypto.php

示例8: do_encrypt

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));
}
開發者ID:giulianofiorotto,項目名稱:IoT-Framework-ESP8266,代碼行數:7,代碼來源:functions.php

示例9: encrypt

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));
}
開發者ID:bismay4u,項目名稱:netsysAgent,代碼行數:7,代碼來源:agent.php

示例10: encrypt

 /**
  *
  * 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))));
 }
開發者ID:skinnard,項目名稱:FTL-2,代碼行數:41,代碼來源:class-encryption.php

示例11: encrypt

 public static function encrypt($text, $key = '')
 {
     if (!$text) {
         return '';
     }
     return @bin2hex(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $text, MCRYPT_MODE_ECB));
 }
開發者ID:phpengineer,項目名稱:tinyPHP,代碼行數:7,代碼來源:crypt.php

示例12: encryptString

 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;
 }
開發者ID:CE-Webmaster,項目名稱:CE-Hub,代碼行數:7,代碼來源:Data.php

示例13: encryptedSerialize

 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);
 }
開發者ID:paulvl,項目名稱:jwt-guard,代碼行數:7,代碼來源:Serializer.php

示例14: a2b_encrypt

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;
}
開發者ID:saydulk,項目名稱:a2billing,代碼行數:7,代碼來源:Misc.php

示例15: ecryptdString

	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;
	}
開發者ID:royalwang,項目名稱:saivi,代碼行數:7,代碼來源:Router.class.php


注:本文中的mcrypt_encrypt函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。