Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example usage of reversible encryption and decryption function in PHP

2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly explains "reversible encryption and decryption function example usage in PHP". The explanation content in this article is simple and clear, easy to learn and understand. Please follow the idea of Xiaobian and go deep into it slowly to study and learn "reversible encryption and decryption function example usage in PHP" together!

Function source code

The copy code is as follows:

function encrypt($data, $key) {

$prep_code = serialize($data);

$block = mcrypt_get_block_size('des', 'ecb');

if (($pad = $block - (strlen($prep_code) % $block))

< $block) { $prep_code .= str_repeat(chr($pad), $pad); } $encrypt = mcrypt_encrypt(MCRYPT_DES, $key, $prep_code, MCRYPT_MODE_ECB); return base64_encode($encrypt); } function decrypt($str, $key) { $str = base64_decode($str); $str = mcrypt_decrypt(MCRYPT_DES, $key, $str, MCRYPT_MODE_ECB); $block = mcrypt_get_block_size('des', 'ecb'); $pad = ord($str[($len = strlen($str)) - 1]); if ($pad && $pad < $block && preg_match('/' . chr($pad) . '{' . $pad . '}$/', $str)) { $str = substr($str, 0, strlen($str) - $pad); } return unserialize($str); } 调用函数 复制代码 代码如下: $key = 'okyo.cn'; $data = array('id' =>

100, 'username' => 'customer', 'password' => 'e10adc3949ba59abbe56e057f20f883e');

$snarr = serialize($data);

$en = encrypt($data, $key);

$de = decrypt($en, $key);

echo "Encryption Prototype: ";

print_r($data);

echo "

Key: $key

Encryption result: $en

Decryption result: ";

print_r($de);

Thank you for reading, the above is the "reversible encryption decryption function instance usage in PHP" content, after the study of this article, I believe we have a deeper understanding of the reversible encryption decryption function instance usage in PHP, the specific use of the situation also needs to be verified by practice. Here is, Xiaobian will push more articles related to knowledge points for everyone, welcome to pay attention!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report