During website development, you often need to encrypt some data (such as user passwords). This article mainly introduces several common encryption functions of PHP during website development, it is often necessary to encrypt some data (such as user passwords). This article mainly introduces several common encryption functions of PHP.
MD5 encryption:
string md5 ( string $str [, bool $raw_output = false ] )
1. by default, md5 () returns a hash value in the hexadecimal format of 32 characters. it accepts two parameters: the first is the string to be encrypted, and the second is the Boolean value of raw_output, the default value is false. if it is set to true, md5 () will return the original 16-bit binary message digest.
2. md5 () is one-way encryption, and there is no reverse decryption algorithm. However, it can still be used to crack common strings through methods such as collection, enumeration, and collision.
Crypt encryption:
string crypt ( string $str [, string $salt ] )
1. crypt () accepts two parameters: the first is the string to be encrypted, and the second is the salt value (that is, the encrypted interference value. if not provided, it is automatically generated by PHP by default ); returns the hash string or a string less than 13 characters, which is used to distinguish the salt value.
2. crypt () is one-way encryption, which is the same as md5.
Sha1 encryption:
string sha1 ( string $str [, bool $raw_output = false ]
1. unlike md5, sha1 () returns a 40-character hash value by default. the input parameter is of the same nature, and the first is an encrypted string, the second is a Boolean value of raw_output. the default value is false. if it is set to true, sha1 () will return the original 20-bit original format message digest.
2. sha1 () is also single-line encryption, with no reverse decryption algorithm
Urlencode encryption:
string urlencode ( string $str )
1. a parameter that is used to pass in the string to be encrypted (usually used to encrypt the URL ),
2. urlencode is bidirectional encryption, which can be encrypted using urldecode (strictly speaking, it is not actually encrypted)
3. returns a string -_. all other non-alphanumeric characters will be replaced with a semicolon (%) followed by two hexadecimal numbers, and spaces will be encoded as the plus sign (+ ).
% 3F ==>%3d %=>%25 ==>%26 \=> % 5C +=> % 2B space =>+ */
Base64 encryption:
string base64_decode ( string $encoded_data )
1. base64_encode () accepts a parameter, that is, the data to be encoded (this is not a string here, because base64 is often used to encode images)
2. base64_encode () is bidirectional encryption and can be decrypted using base64_decode ().
Example of an image:
The above is the content of several common encryption functions in PHP (Advanced article). For more information, see PHP Chinese network (www.php1.cn )!