Home > Backend Development > PHP Problem > How to perform md5 encryption in php

How to perform md5 encryption in php

(*-*)浩
Release: 2023-02-24 13:08:01
Original
4962 people have browsed it

How to perform md5 encryption in php

DirectlyYou canuse the md5() function to encrypt the content, such as: md5($admin_pw).

Divide this ciphertext into several segments, perform an MD5 operation on each segment, then concatenate this pile of ciphertext into a very long string, and finally perform another MD5 operation. The resulting ciphertext is still 32 bits in length. (Recommended learning: PHP programming from entry to proficiency)

<?php
//把密文分割成两段,每段16个字符
function md5_2_1($data)
{
//先把密码加密成长度为32字符的密文
$data = md5($data);
//把密码分割成两段
$left = substr($data, 0, 16);
$right = substr($data, 16, 16);
//分别加密后再合并
$data = md5($left).md5($right);
//最后把长字串再加密一次,成为32字符密文
return md5($data);
}
//把密文分割成32段,每段1个字符
function md5_2_2($data)
{
$data = md5($data);
//循环地截取密文中的每个字符并进行加密、连接
for ($i = 0; $i < 32; $i++) {
$data .= md5($data{$i});
}
//这时$data长度为1024个字符,再进行一次MD5运算
return md5($data);
}
?>
Copy after login

The above is the detailed content of How to perform md5 encryption in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template