当前位置: 首页>>代码示例>>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;未经允许,请勿转载。