Home Backend Development PHP Tutorial PHP mcrypt encryption and decryption function

PHP mcrypt encryption and decryption function

Aug 08, 2016 am 09:25 AM
data mcrypt size

加密

function mcrypt_encode ($data, $key) {
    $init_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_CBC);
    $init_vect = mcrypt_create_iv($init_size, MCRYPT_RAND);
    $data = $init_vect . mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $data, MCRYPT_MODE_CBC, $init_vect);
    return $data;
}
Copy after login

解密
function mcrypt_decode ($data, $key) {
    $init_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_CBC);
    if ($init_size > strlen($data)) {
        return false;
    }
    $init_vect = substr($data, 0, $init_size);
    $data = substr($data, $init_size);
    return rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key, $data, MCRYPT_MODE_CBC, $init_vect), "\0");
}
Copy after login

以上就介绍了PHP mcrypt 加密解密函数,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

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)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks 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)

Use java's File.length() function to get the size of the file Use java's File.length() function to get the size of the file Jul 24, 2023 am 08:36 AM

Use Java's File.length() function to get the size of a file. File size is a very common requirement when dealing with file operations. Java provides a very convenient way to get the size of a file, that is, using the length() method of the File class. . This article will introduce how to use this method to get the size of a file and give corresponding code examples. First, we need to create a File object to represent the file we want to get the size of. Here is how to create a File object: Filef

How to replace mcrypt in php How to replace mcrypt in php Oct 31, 2022 am 09:46 AM

How to replace mcrypt with php: 1. Open the corresponding php file; 2. Find the original encryption and decryption code; 3. Use the "openssl_encrypt" and "openssl_decrypt" methods to replace it.

What data is in the data folder? What data is in the data folder? May 05, 2023 pm 04:30 PM

The data folder contains system and program data, such as software settings and installation packages. Each folder in the Data folder represents a different type of data storage folder, regardless of whether the Data file refers to the file name Data or the extension. Named data, they are all data files customized by the system or program. Data is a backup file for data storage. Generally, it can be opened with meidaplayer, notepad or word.

Use the size() method of the TreeSet class to get the number of elements in the tree collection Use the size() method of the TreeSet class to get the number of elements in the tree collection Jul 24, 2023 am 11:05 AM

Title: Use the size() method of the TreeSet class to obtain the number of elements in the tree collection. Introduction TreeSet is an ordered collection in the Java collection framework. It implements the SortedSet interface and uses the red-black tree data structure to implement it. TreeSet can be sorted according to the natural order of elements, or by using a Comparator custom comparator. This article will introduce how to use the size() method of the TreeSet class to obtain the number of elements in the tree collection and provide

What to do if mysql load data is garbled? What to do if mysql load data is garbled? Feb 16, 2023 am 10:37 AM

The solution to the garbled mysql load data: 1. Find the SQL statement with garbled characters; 2. Modify the statement to "LOAD DATA LOCAL INFILE "employee.txt" INTO TABLE EMPLOYEE character set utf8;".

Detailed tutorial on performance optimization of MySQL database on Linux system. Detailed tutorial on performance optimization of MySQL database on Linux system. Feb 19, 2024 pm 05:51 PM

The following is a detailed tutorial on MySQL database performance optimization under Linux systems: Optimize configuration file: Open the MySQL configuration file (usually my.cnf or my.ini). Adjust the following parameters to optimize performance: key_buffer_size: Adjust the index cache size to fit the size of your data. innodb_buffer_pool_size: Adjust the InnoDB buffer pool size to suit your data size. innodb_log_file_size: Adjust the InnoDB log file size to fit your write load. query_cache_size: Enable and resize the query cache. max_connection

What are the differences between xdata and data What are the differences between xdata and data Dec 11, 2023 am 11:30 AM

The differences are: 1. xdata usually refers to independent variables, while data refers to the entire data set; 2. xdata is mainly used to establish data analysis models, while data is used for data analysis and statistics; 3. xdata is usually used for regression Analysis, variance analysis, predictive modeling, data can be analyzed using various statistical methods; 4. xdata usually requires data preprocessing, and data can contain complete original data.

AI project failure rates top 80% — study cites poor problem recognition and a focus on latest tech trends among major problems AI project failure rates top 80% — study cites poor problem recognition and a focus on latest tech trends among major problems Aug 31, 2024 am 12:59 AM

Everyone and their aunt seem to be hopping aboard the AI train in search of inflated profit margins and marketing hype — just look at AMD's recent Ryzen rebrand as a prime example of this AI hype. A recent study conducted by RAND has found that this

See all articles