Table of Contents
Repair code of the classic PHP encryption and decryption function Authcode(), encryption and decryption authcode
Home Backend Development PHP Tutorial Classic PHP encryption and decryption function Authcode() repair version code, encryption and decryption authcode_PHP tutorial

Classic PHP encryption and decryption function Authcode() repair version code, encryption and decryption authcode_PHP tutorial

Jul 13, 2016 am 09:58 AM
php encryption and decryption encrypt and decode

Repair code of the classic PHP encryption and decryption function Authcode(), encryption and decryption authcode

Authcode is a function that many people use. This function comes from the Discuz program and is used to encrypt and decrypt strings. , you can set the key and expiration time, which is useful in many cases. The original function code may generate characters such as , /, &, which will cause them to be escaped when the value is returned through the URL, making it impossible to decrypt. Fireend Network made a slight modification, replaced these characters with other characters, and then replaced them back during decryption, so it was perfect!

The code is as follows:

function authcode($string, $operation = 'DECODE', $key = '', $expiry = 0){
 
 if($operation == 'DECODE') {
 $string = str_replace('[a]','+',$string);
 $string = str_replace('[b]','&',$string);
 $string = str_replace('[c]','/',$string);
 }
 $ckey_length = 4;
 $key = md5($key ? $key : 'livcmsencryption ');
 $keya = md5(substr($key, 0, 16));
 $keyb = md5(substr($key, 16, 16));
 $keyc = $ckey_length ? ($operation == 'DECODE' ? substr($string, 0, $ckey_length): substr(md5(microtime()), -$ckey_length)) : '';
 $cryptkey = $keya.md5($keya.$keyc);
 $key_length = strlen($cryptkey);
 $string = $operation == 'DECODE' ? base64_decode(substr($string, $ckey_length)) : sprintf('%010d', $expiry ? $expiry + time() : 0).substr(md5($string.$keyb), 0, 16).$string;
 $string_length = strlen($string);
 $result = '';
 $box = range(0, 255);
 $rndkey = array();
 for($i = 0; $i <= 255; $i++) {
  $rndkey[$i] = ord($cryptkey[$i % $key_length]);
 }
 for($j = $i = 0; $i < 256; $i++) {
  $j = ($j + $box[$i] + $rndkey[$i]) % 256;
  $tmp = $box[$i];
  $box[$i] = $box[$j];
  $box[$j] = $tmp;
 }
 for($a = $j = $i = 0; $i < $string_length; $i++) {
  $a = ($a + 1) % 256;
  $j = ($j + $box[$a]) % 256;
  $tmp = $box[$a];
  $box[$a] = $box[$j];
  $box[$j] = $tmp;
  $result .= chr(ord($string[$i]) ^ ($box[($box[$a] + $box[$j]) % 256]));
 }
 if($operation == 'DECODE') {
  if((substr($result, 0, 10) == 0 || substr($result, 0, 10) - time() > 0) && substr($result, 10, 16) == substr(md5(substr($result, 26).$keyb), 0, 16)) {
 
   return substr($result, 26);
  } else {
   return '';
  }
 } else {
 $ustr = $keyc.str_replace('=', '', base64_encode($result));
 $ustr = str_replace('+','[a]',$ustr);
 $ustr = str_replace('&','[b]',$ustr);
 $ustr = str_replace('/','[c]',$ustr);
  return $ustr;
 }
}
Copy after login

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/979705.htmlTechArticleThe classic PHP encryption and decryption function Authcode() repair version code, encryption and decryption authcode Authcode is a function that many people use. This The function comes from the Discuz program and is used to encrypt and decrypt strings. It can...
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Two Point Museum: All Exhibits And Where To Find Them
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to add Win11 encryption function to the right-click menu? How to add Win11 encryption and decryption right-click shortcut How to add Win11 encryption function to the right-click menu? How to add Win11 encryption and decryption right-click shortcut Jan 07, 2024 am 08:45 AM

This article is a tutorial on how to encrypt and decrypt files without using third-party encryption and decryption tools. A tutorial on adding encryption and decryption methods to the right-click menu of Win11. Since the registry needs to be modified, you must make a backup before proceeding. operate. 1. First, press the [Win+R] key combination on the keyboard to open Run, then enter the [regedit] command and press [OK or Enter] to open the Registry Editor; 2. In the User Account Control window, you need to allow Does this app make changes to your device? Click [Yes]; 3. Registry Editor window, expand to the following path: HKEY_CURRENT_USER\Software\Microsoft\Windows\Curr

Encrypt and decrypt sensitive data using Yii framework middleware Encrypt and decrypt sensitive data using Yii framework middleware Jul 28, 2023 pm 07:12 PM

Encrypting and decrypting sensitive data using Yii framework middleware Introduction: In modern Internet applications, privacy and data security are very important issues. To ensure that users' sensitive data is not accessible to unauthorized visitors, we need to encrypt this data. The Yii framework provides us with a simple and effective way to implement the functions of encrypting and decrypting sensitive data. In this article, we’ll cover how to achieve this using the Yii framework’s middleware. Introduction to Yii framework Yii framework is a high-performance PHP framework.

Data encryption and decryption using React Query and database Data encryption and decryption using React Query and database Sep 26, 2023 pm 12:53 PM

Title: Data Encryption and Decryption Using ReactQuery and Database Introduction: This article will introduce how to use ReactQuery and database for data encryption and decryption. We will use ReactQuery as the data management library and combine it with the database to perform data encryption and decryption operations. By combining these two technologies, we can securely store and transmit sensitive data, and perform encryption and decryption operations when needed to ensure data security. Text: 1. ReactQue

Encryption and decryption implementation method developed in PHP in WeChat applet Encryption and decryption implementation method developed in PHP in WeChat applet Jun 01, 2023 am 08:12 AM

As WeChat mini programs become more popular in the mobile application market, their development has also received more and more attention. In small programs, PHP, as a commonly used back-end language, is often used to handle the encryption and decryption of sensitive data. This article will introduce how to use PHP to implement encryption and decryption in WeChat applet. 1. What are encryption and decryption? Encryption is the conversion of sensitive data into an unreadable form to ensure that the data is not stolen or tampered with during transmission. Decryption is the restoration of encrypted data to original data. In small programs, encryption and decryption usually include

What are the methods for php encryption and decryption? What are the methods for php encryption and decryption? Feb 23, 2024 pm 03:09 PM

What are the methods for PHP encryption and decryption? Specific code examples are required. With the continuous development of network technology, data security has attracted more and more attention. In the web development process, handling and protecting users' sensitive information is an essential part. PHP, as a scripting language widely used in web development, provides a variety of methods in data encryption and decryption. Several commonly used encryption and decryption methods will be introduced below and corresponding code examples will be provided. 1. Symmetric encryption Symmetric encryption algorithms use the same key for encryption and decryption. Common symmetry additions

PHP mailbox development: implementing email encryption and decryption functions PHP mailbox development: implementing email encryption and decryption functions Sep 12, 2023 am 10:40 AM

PHP mailbox development: realizing email encryption and decryption functions. With the increasing development of information transmission, email has become one of the important communication methods for people. However, the ensuing security issues have gradually attracted people's attention. In order to protect the security of emails, encryption and decryption have become important aspects of sending and receiving emails. This article will introduce how to use PHP to develop email encryption and decryption functions to improve email security. 1. Principle and function of encryption Email encryption is to convert the email content using a specific algorithm so that in addition to the recipient

Example of data encryption and decryption in PHP Tencent Cloud Server API interface docking Example of data encryption and decryption in PHP Tencent Cloud Server API interface docking Jul 05, 2023 pm 06:16 PM

Examples of data encryption and decryption in PHP Tencent Cloud Server API interface docking With the widespread application of cloud servers, more and more developers have begun to deploy their applications to cloud servers. In the process of connecting with the Tencent Cloud server API interface, data encryption and decryption is an important link. This article will introduce an example of data encryption and decryption in PHP. When connecting to the Tencent Cloud server API interface, we usually need to encrypt some sensitive data to ensure data security. At the same time, it is also necessary to pick up

Example of data encryption and decryption during PHP Tencent Cloud Server API interface docking process Example of data encryption and decryption during PHP Tencent Cloud Server API interface docking process Jul 06, 2023 am 10:52 AM

Introduction to data encryption and decryption examples in the process of docking with the API interface of Tencent Cloud Server using PHP: In the process of docking with the API interface of Tencent Cloud Server, the security of data is very important. In order to ensure the security of data during transmission and storage, we need to encrypt sensitive information. This article will introduce how to use PHP to encrypt and decrypt data to improve data confidentiality and integrity. Data encryption: When making API requests, we need to encrypt sensitive information to ensure data security. common

See all articles