ÔõÑùÔÚThinkPHP6ÖоÙÐÐÊý¾Ý¼ÓÃÜÏ¢ÕùÃܲÙ×÷£¿
Ëæ×Å»¥ÁªÍøÊÖÒÕµÄÒ»Ö±Éú³¤£¬Êý¾Ý¼ÓÃÜÏ¢ÕùÃÜÒѾ³ÉΪÁËÎÒÃÇÒ»Ñùƽ³£¿ª·¢Öбز»¿ÉÉÙµÄÒ»²¿·Ö¡£ÔÚthinkphp6ÖУ¬Êý¾Ý¼ÓÃÜÏ¢ÕùÃÜͬÑùÊÇÒ»¸ö·Ç¾³£¼ûµÄÐèÇ󣬱¾ÎĽ«ÏÈÈÝÔõÑùÔÚthinkphp6ÖоÙÐÐÊý¾Ý¼ÓÃÜÏ¢ÕùÃܲÙ×÷¡£
Êý¾Ý¼ÓÃÜ
ÔÚThinkPHP6ÖУ¬ÎÒÃÇ¿ÉÒÔͨ¹ýŲÓÿò¼Ü×Ô´øµÄ¼ÓÃÜÀàCryptÀ´ÊµÏÖÊý¾Ý¼ÓÃÜ¡£CryptÖÐÌṩÁËÐí¶à²î±ðµÄ¼ÓÃÜËã·¨£¬ÀýÈçAES¡¢DESµÈ¡£
ÎÒÃÇ¿ÉÒÔͨ¹ýÒÔÏ°취À´¾ÙÐÐÊý¾Ý¼ÓÃÜ£º
1.1 ÒýÈëCryptÀà
ÔÚÎÒÃǵĿØÖÆÆ÷ÖУ¬ÐèÒªÏÈÒýÈëCryptÀࣺ
Á¬Ã¦Ñ§Ï°¡°PHPÃâ·ÑѧϰÌõ¼Ç£¨ÉîÈ룩¡±£»
use thinkacadeCrypt;
1.2 ¼ÓÃÜÊý¾Ý
ÔÚÐèÒª¼ÓÃÜÊý¾ÝµÄµØ·½£¬ÎÒÃÇ¿ÉÒÔʹÓÃCryptµÄencryptÒªÁìÀ´¾ÙÐмÓÃÜ¡£ÀýÈ磺
$data = ‘ÐèÒª¼ÓÃܵÄÊý¾Ý’;
$key = ‘¼ÓÃÜÃÜÔ¿’;
$encryptedData = Crypt::encrypt($data, $key);
ÔÚÉÏÃæµÄ´úÂëÖУ¬$dataÌåÏÖÐèÒª¼ÓÃܵÄÊý¾Ý£¬$keyÌåÏÖ¼ÓÃÜÃÜÔ¿£¬$encryptedDataÔòÊǼÓÃܺóµÄЧ¹û¡£
ÐèҪעÖصÄÊÇ£¬$keyµÄ³¤¶È±ØÐèΪ16룬²»È»¼ÓÃÜ»áʧ°Ü¡£
Êý¾Ý½âÃÜ
ÔÚÎüÊÕµ½¼ÓÃÜÊý¾Ýºó£¬ÎÒÃÇͬÑù¿ÉÒÔͨ¹ýCryptÀàÀ´¾ÙÐÐÊý¾ÝµÄ½âÃܲÙ×÷¡£Ïêϸ°ì·¨ÈçÏ£º
2.1 ÒýÈëCryptÀà
ͬÑùµØ£¬ÔÚÎÒÃǵĿØÖÆÆ÷ÖÐÐèÒªÏÈÒýÈëCryptÀࣺ
use thinkacadeCrypt;
2.2 ½âÃÜÊý¾Ý
ÔÚÐèÒª¾ÙÐнâÃܲÙ×÷µÄµØ·½£¬ÎÒÃÇ¿ÉÒÔʹÓÃCryptµÄdecryptÒªÁìÀ´¾ÙÐнâÃÜ¡£ÀýÈ磺
$encryptedData = ‘ÐèÒª½âÃܵÄÊý¾Ý’;
$key = ‘¼ÓÃÜÃÜÔ¿’;
$data = Crypt::decrypt($encryptedData, $key);
ÔÚÉÏÃæµÄ´úÂëÖУ¬$encryptedDataÌåÏÖÐèÒª½âÃܵÄÊý¾Ý£¬$keyÌåÏÖ¼ÓÃÜÃÜÔ¿£¬$dataÔòÊǽâÃܺóµÄЧ¹û¡£
ÐèҪעÖصÄÊÇ£¬¼ÓÃÜÏ¢ÕùÃܵÄÃÜÔ¿±ØÐèÏàͬ£¬²»È»½âÃÜ»áʧ°Ü¡£
×ܽá
ͨ¹ýÒÔÉÏ°ì·¨£¬ÎÒÃÇÒѾÀֳɵØÔÚThinkPHP6ÖÐÍê³ÉÁËÊý¾Ý¼ÓÃÜÏ¢ÕùÃܲÙ×÷¡£ÐèҪעÖصÄÊÇ£¬ÔÚÏÖʵ¿ª·¢ÖУ¬ÎÒÃÇÓ¦¸Ãƾ֤ÏêϸµÄÐèÇóÑ¡ÔñºÏÊʵļÓÃÜ·½·¨ºÍ¼ÓÃÜÃÜÔ¿£¬ÒÔÈ·±£Êý¾ÝµÄÇå¾²ÐÔ¡£
ͬʱ£¬ÓÉÓÚ±¾ÎÄÖ»ÏÈÈÝÁËÔõÑù»ùÓÚ¿ò¼Ü×Ô´øµÄ¼ÓÃÜÀà¾ÙÐÐÊý¾Ý¼ÓÃÜÏ¢ÕùÃܲÙ×÷£¬ÉÐÓÐÐí¶àÆäËûµÄ¼ÓÃÜ·½·¨ºÍ¹¤¾ß¿É¹©Ñ¡Ôñ¡£ÁÐλ¿ª·¢Õß¿ÉÒÔƾ֤ÏÖʵÐèÇóÑ¡Ôñ×îºÏÊʵļÓÃÜ·½·¨¡£
ÒÔÉϾÍÊÇÔõÑùÔÚThinkPHP6ÖоÙÐÐÊý¾Ý¼ÓÃÜÏ¢ÕùÃܲÙ×÷£¿µÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡