尊龙凯时人生就是搏

thinkphp¼ÓÃÜÒªÁì

×î½ü £¬Ô½À´Ô½¶àµÄÍøÕ¾×îÏÈʹÓÃthinkphp¿ò¼ÜÀ´¿ª·¢ºÍά»¤×Ô¼ºµÄÍøÕ¾¡£ÕâÊÇÓÉÓÚthinkphp¿ò¼Ü¾ßÓÐÐí¶àÓŵã £¬ºÃ±ÈÒ×ÓÚѧϰ¡¢Ç¿Ê¢µÄÄ£°åÒýÇæ¡¢Çå¾²ÐԸߵȵÈ¡£È»¶øÔÚ¿ª·¢Àú³ÌÖÐ £¬ÐèҪעÖØÊý¾ÝÇå¾²µÄÎÊÌâ £¬ÆäÖÐÒ»ÏîÖ÷ÒªµÄʹÃü¾ÍÊǼÓÃÜÊý¾Ý¡£±¾ÎĽ«»á̽ÌÖthinkphpÖмÓÃÜÊý¾ÝµÄÒªÁì¡£

ʹÓÃϵͳ×Ô´øµÄ¼ÓÃܺ¯Êý

thinkphp¿ò¼ÜÖÐ×Ô´øµÄ¼ÓÃܺ¯ÊýΪthinkhelperHash::make($str)¡£Õâ¸öº¯Êý¿ÉÒÔÓÃÀ´¼ÓÃÜ×Ö·û´®£¨$str£©¡£

ʹÓÃÒªÁìÈçÏ£º

$str = 'Hello World';
$encrypt_str = thinkhelperHash::make($str);

µÇ¼ºó¸´ÖÆ

¼ÓÃܺóµÄ×Ö·û´®$encrypt_str £¬ËüÊÇÒ»¸ö40λµÄËæ»ú×Ö·û´®¡£ÕâÖÖÒªÁìÊÇÒ»¸ö»ùÓÚ¹þÏ£Ëã·¨µÄ¼òÆÓ¼ÓÃÜÒªÁì £¬¹ØÓÚһЩ¼òÆӵij¡¾°ÊÇ×ã¹»µÄ¡£

ʹÓõÚÈý·½¿â

³ýÁËϵͳ×Ô´øµÄ¼ÓÃܺ¯ÊýÖ®Íâ £¬thinkphp»¹Ö§³ÖÒýÈëµÚÈý·½¿â¾ÙÐмÓÃÜ¡£ºÃ±È¿ÉÒÔʹÓÃPHP¼ÓÃÜÀ©Õ¹¿âsodiumÀ´¾ÙÐÐÊý¾Ý¼ÓÃÜ¡£

Á¬Ã¦Ñ§Ï°¡°PHPÃâ·ÑѧϰÌõ¼Ç£¨ÉîÈ룩¡±£»

ʹÓÃÒªÁìÈçÏ£º

Ê×ÏÈÐèҪװÖÃsodiumÀ©Õ¹¿â £¬Ê¹ÓÃÏÂÁ

pecl install libsodium

µÇ¼ºó¸´ÖÆ

×°ÖÃÍê³Éºó £¬ÐèÒªÔÚphp.iniÎļþÖмÓÈëÒ»ÐУº

extension=sodium.so

µÇ¼ºó¸´ÖÆ

È»ºóÔÚ´úÂëÖÐʹÓüÓÃܺ¯Êý¾ÙÐмÓÃÜ £¬ÔÚsodium¿âÖÐ £¬¼ÓÃܺ¯ÊýΪsodium_crypto_secretbox($str, $nonce, $secretKey)¡£

ÆäÖÐ £¬$strΪÐèÒª¼ÓÃܵÄ×Ö·û´® £¬$nonceΪΨһµÄ×Ö·û´® £¬$secretKeyΪÃÜÔ¿¡£

ʹÓÃÒªÁìÈçÏ£º

$str = 'Hello World';
$nonce = random_bytes(SODIUM_CRYPTO_SECRETBOX_NONCEBYTES);
$secretKey = sodium_crypto_secretbox_keygen();
$encrypt_str = sodium_crypto_secretbox($str, $nonce, $secretKey);

µÇ¼ºó¸´ÖÆ

¼ÓÃܺóµÄ$encrypt_str £¬¿ÉÒÔʹÓÃÏàͬµÄÃÜÔ¿ºÍnonceÀ´¾ÙÐнâÃÜ¡£

×Ô½ç˵¼ÓÃÜÒªÁì

ÈôÊÇÏëÒªÔ½·¢Çå¾²µÄ¼ÓÃÜ·½·¨ £¬¿ÉÒÔ×Ô½ç˵¼ÓÃܺ¯Êý»òÕßŲÓõÚÈý·½µÄ¿â¾ÙÐмÓÃÜ¡£

ʹÓÃ×Ô½ç˵¼ÓÃܺ¯ÊýµÄÒªÁìÈçÏ£º

function my_encrypt($data, $key){
    $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),
            $data,
            MCRYPT_MODE_CBC,
            $iv
        )
    );
    return $encrypted;
}

µÇ¼ºó¸´ÖÆ

ÕâÊÇÒ»¸ö»ùÓÚaes-256-ctrËã·¨µÄ¼ÓÃܺ¯Êý £¬¿ÉÒÔ×Ô½ç˵ÃÜÔ¿ºÍ¼ÓÃÜÊý¾Ý¡£¿ÉÊÇÐèҪעÖصÄÊÇ £¬mcryptÒѾ­ÔÚPHP 7.2°æ±¾Öб»·ÅÆú £¬Òò´ËÐèÒª×ÔÐÐÑ°ÕÒÌæ»»µÄÒªÁì¡£

×ܽá

Êý¾ÝÇå¾²ÊÇÒ»¸öÍøÕ¾¿ª·¢Àú³ÌÖбØÐèҪ˼Á¿µÄÎÊÌâ¡£ÔÚthinkphp¿ò¼ÜÖÐ £¬¿ÉÒÔͨ¹ýϵͳ×Ô´øµÄ¼ÓÃܺ¯Êý¡¢µÚÈý·½¿â»òÕß×Ô½ç˵¼ÓÃܺ¯Êý £¬À´°ü¹ÜÊý¾ÝµÄÇå¾²ÐÔ¡£¿ÉÊÇÐèҪƾ֤ÏêϸµÄÐèÇóÀ´Ñ¡ÔñºÏÊʵļÓÃÜ·½·¨ £¬ÒÔµÖ´ï×î¼ÑµÄЧ¹û¡£

ÒÔÉϾÍÊÇthinkphp¼ÓÃÜÒªÁìµÄÏêϸÄÚÈÝ £¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

ÃâÔð˵Ã÷£ºÒÔÉÏչʾÄÚÈÝȪԴÓÚÏàÖúýÌå¡¢ÆóÒµ»ú¹¹¡¢ÍøÓÑÌṩ»òÍøÂçÍøÂçÕûÀí £¬°æȨÕùÒéÓë±¾Õ¾ÎÞ¹Ø £¬ÎÄÕÂÉæ¼°¿´·¨Óë¿´·¨²»´ú±í尊龙凯时人生就是搏ÂËÓÍ»úÍø¹Ù·½Ì¬¶È £¬Çë¶ÁÕß½ö×ö²Î¿¼¡£±¾ÎĽӴýתÔØ £¬×ªÔØÇë˵Ã÷À´ÓÉ¡£ÈôÄúÒÔΪ±¾ÎÄÇÖÕ¼ÁËÄúµÄ°æȨÐÅÏ¢ £¬»òÄú·¢Ã÷¸ÃÄÚÈÝÓÐÈκÎÉæ¼°ÓÐÎ¥¹«µÂ¡¢Ã°·¸Ö´·¨µÈÎ¥·¨ÐÅÏ¢ £¬ÇëÄúÁ¬Ã¦ÁªÏµ尊龙凯时人生就是搏ʵʱÐÞÕý»òɾ³ý¡£

Ïà¹ØÐÂÎÅ

ÁªÏµ尊龙凯时人生就是搏

18523999891

¿É΢ÐÅÔÚÏß×Éѯ

ÊÂÇéʱ¼ä£ºÖÜÒ»ÖÁÖÜÎå £¬9:30-18:30 £¬½ÚãåÈÕÐÝÏ¢

QR code
sitemap¡¢ÍøÕ¾µØͼ