<?php class Xcrypt{ private $mcrypt; private $key; private $mode; private $iv; private $blocksize; public function __construct($key, $mode = 'cbc', $iv = "off"){ switch (strlen($key)){ case 8: $this->mcrypt = MCRYPT_DES; break; case 16: $this->mcrypt = MCRYPT_RIJNDAEL_128; break; case 32: $this->mcrypt = MCRYPT_RIJNDAEL_256; break; default: die("Key size must be 8/16/32"); }
Commonly used symmetric encryption algorithm class
Supported key: 64/128/256 bit (byte length 8/16/32)
Supported algorithm: DES/AES (according to the key Key length automatic matching uses: DES: 64bit AES: 128/256bit)
Supported mode: CBC/ECB/OFB/CFB
Ciphertext encoding: base64 string/hexadecimal character String/binary string stream
Padding method: PKCS5Padding (DES)
All resources on this site are contributed by netizens or reprinted by major download sites. Please check the integrity of the software yourself! All resources on this site are for learning reference only. Please do not use them for commercial purposes. Otherwise, you will be responsible for all consequences! If there is any infringement, please contact us to delete it. Contact information: admin@php.cn
Related Article
13 Jul 2016
PHP symmetric encryption algorithm example. PHP symmetric encryption algorithm KEY is a constant defined before. Copy the code. The code is as follows: Mcrypt::encrypt(); Mcrypt::decrypt(); Copy the code. The code is as follows: defined('ROOT') or exit('Access Denie
25 Jul 2016
Symmetric encryption algorithm provided by php
25 Jul 2016
PHP symmetric encryption algorithm (DES/AES) code
26 May 2018
Recently, I suddenly wanted to save some confidential things in the database, and then I thought about how to prevent others from understanding what is stored even if they enter the database, so the only way is to encrypt it; but we still have to read it ourselves, so we can only Find some symmetric encryption algorithms and decrypt them when we want to see them. The following introduces the implementation of a simple symmetric encryption algorithm in PHP.
07 Jan 2017
Recently, I suddenly wanted to save some confidential things in the database, and then I thought about how to prevent others from understanding what is stored even if they enter the database, so the only way is to encrypt it; but we still have to read it ourselves, so we can only Find some symmetric encryption algorithms and decrypt them when we want to see them. The following introduces the implementation of a simple symmetric encryption algorithm in PHP.
16 Mar 2019
This article brings you an introduction to PHP's simple symmetric encryption algorithm (code example). It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.
Hot Tools
PHP library for dependency injection containers
PHP library for dependency injection containers
A collection of 50 excellent classic PHP algorithms
Classic PHP algorithm, learn excellent ideas and expand your thinking
Small PHP library for optimizing images
Small PHP library for optimizing images