search
HomePHP LibrariesOther librariesPHP class for symmetric encryption algorithm
PHP class for symmetric encryption algorithm
<?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)


Disclaimer

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

PHP symmetric encryption algorithm example_PHP tutorialPHP symmetric encryption algorithm example_PHP tutorial

13Jul2016

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

Symmetric encryption algorithm provided by phpSymmetric encryption algorithm provided by php

25Jul2016

Symmetric encryption algorithm provided by php

PHP symmetric encryption algorithm (DES/AES) codePHP symmetric encryption algorithm (DES/AES) code

25Jul2016

PHP symmetric encryption algorithm (DES/AES) code

Implementation of symmetric encryption algorithm in phpImplementation of symmetric encryption algorithm in php

26May2018

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.

Simple symmetric encryption algorithm implementation in phpSimple symmetric encryption algorithm implementation in php

07Jan2017

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.

Introduction to PHP simple symmetric encryption algorithm (code example)Introduction to PHP simple symmetric encryption algorithm (code example)

16Mar2019

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.

See all articles