Home >Backend Development >PHP Tutorial >Reversible encryption algorithm that can be shared between PHP and asp.net C#_PHP tutorial
Because of the work requirements, we need to generate encryption in PHP and then decrypt the password received in asp.net. Below I found a reversible encryption algorithm that can be shared between PHP and asp.net C#. Students who need to know more can refer to it.
php encryption algorithm
The code is as follows | Copy code | ||||
{ var $key; var $iv; // partial Shift amount function DES($key = '11001100', $iv=0) { //key length 8, for example: 1234abcd $this->key = $ key; ->iv = $iv; //mcrypt_create_iv ( mcrypt_get_block_size (MCRYPT_DES, MCRYPT_MODE_CBC), MCRYPT_DEV_RANDOM ); . > //Encryption, returns uppercase hexadecimal string $size = mcrypt_get_block_size (MCRYPT_DES, MCRYPT_MODE_CBC); $str = $this->pkcs5Pad ($str, $size); return strtoupper( bin2hex( mcrypt_cbc(MCRYPT_DES, $this->key, $str, MCRYPT_ENCRYPT, $this->iv) ) ); str) { strBin, MCRYPT_DECRYPT, $this->iv ); $str = $this->pkcs5Unpad($str); > function hex2bin($hexData) { $binData = ""; for($i = 0; $i < strlen ( $hexData ); $i += 2) { $binData .= chr ( hexdec ( substr ( $hexData, $i, 2 ) ) ); , $blocksize) { $pad = $blocksize - (strlen ( $text ) % $blocksize); return $text . str_repeat ( chr ( $pad ), $pad ); } . $ Text) Return false; If (STRSPN ($ Text, Chr ($ Pad), Strlen ($ Text) -$ Pad)! = $ Pad) RETURN FALSE; < br /> return substr ($text, 0, - 1 * $pad); |
asp.net program code
The code is as follows | Copy code |
using System; namespace WindowsFormsApplication1 /// |