Introduction to des encryption and decryption functions in php
Source: Internet
Author: User
Des encryption and decryption in php. here we can look at two functions, which are about des encryption and decryption in php. These two functions can encrypt data into complex strings, if you do not decrypt the data, you cannot know how to encrypt and decrypt the des in php. Here we look at two functions: des encryption and decryption in php. These two functions can encrypt the data into complex strings, if you do not decrypt it, you cannot know the content before encryption. you can use des encryption to encrypt and save the password. php's mde encryption and MD5 are both good features of encryption.
The two functions are as follows:
Encryption Function: encrypt
Function encrypt ($ encrypt, $ key = ""){
$ Iv = mcrypt_create_iv (mcrypt_get_iv_size (MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB), MCRYPT_RAND );
$ Passcrypt = mcrypt_encrypt (MCRYPT_RIJNDAEL_256, $ key, $ encrypt, MCRYPT_MODE_ECB, $ iv );
$ Encode = base64_encode ($ passcrypt );
Return $ encode;
}
The following example shows the two functions:
$ New = encrypt ("wo shi old", "111 ");
$ Old = decrypt ($ new, "111 ");
Echo $ new. "the plaintext is :"."
";
Echo $ old;
?>
The running result is:
BnF + S42hS0BzXqMwPJJN82yBa4/DiYoYcTGmt0TotwY = the plaintext is: wo shi old
Note: pay attention to the value of $ key during encryption or decryption. to decrypt the key after encryption, you must know the value of $ key. Otherwise, the correct plaintext cannot be obtained.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.