Home > php教程 > PHP源码 > body text

纯PHP实现的DES加密解密

PHP中文网
Release: 2016-05-25 17:09:16
Original
987 people have browsed it

des加密:

function des_encrypt($str, $key) {
  $block = mcrypt_get_block_size('des', 'ecb');
  $pad = $block - (strlen($str) % $block);
  $str .= str_repeat(chr($pad), $pad);
  return mcrypt_encrypt(MCRYPT_DES, $key, $str, MCRYPT_MODE_ECB);
}
Copy after login

des解密:

function des_decrypt($str, $key) {
  $str = mcrypt_decrypt(MCRYPT_DES, $key, $str, MCRYPT_MODE_ECB);
  $len = strlen($str);
  $block = mcrypt_get_block_size('des', 'ecb');
  $pad = ord($str[$len - 1]);
  return substr($str, 0, $len - $pad);
}
Copy after login
Related labels:
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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template