php encryption algorithm is used to encrypt php code, so what are the php encryption algorithms? In this article, I will share with you several PHP encryption algorithms. Next, let’s take a closer look at what is said in the article.
1.Md5() encryption algorithm - one-way encryption, cannot be decrypted
Syntax: String md5(string $str,$raw =false),
$str: required. Specifies the string to be calculated,
$raw: optional. Specifies hexadecimal or binary output format:
TRUE - raw 16 character binary format
FALSE - default. 32 character hexadecimal number
Return value : Returns the calculated MD5 hash if successful, returns FALSE on failure
2.Crypt() encryption algorithm - also one-way encryption
Syntax: string crypt(string $str, string, $salt),
$str: Required. Specifies the string to be calculated,
$salt, is optional. A string used to increase the number of characters being encoded to make the encoding more secure. If no salt parameter is provided, PHP will randomly generate one each time the function is called.
Return value: Returns a hash string based on the standard UNIX DES algorithm or other alternative algorithms available on the system
Example: 1.crypt('zhangsan' );--Output $1$aX3.sX0.$PcFaGWCv51UNO.1eIvMpy0 (the first $1$aX3.sX0.$ is a randomly given string)
2.crypt('zhangsan','we' );--Output weGSA6nisE59k ("we" is unchanged)
Supported algorithms for various PHP settings:
3.Sha1() encryption algorithm ( One-way encryption)
Syntax: String sha1 (string $str, $raw_output=false),
$str: encrypted string
$raw_output: If the optional raw_output parameter is set to TRUE, the sha1 digest will be returned in raw format with a length of 20 characters, otherwise the return value is a hexadecimal number with a length of 40 characters.
Return value: sha1 hash value string
Note: Like md5, some decryption websites on Baidu can refer to the ciphertext he recorded in advance and the ciphertext we entered. Comparison is performed to obtain the plain text, but it is not a real crack. Encrypting multiple times can prevent this from happening.
4. URL encoding encryption algorithm - two-way
1. urlencode(string $str): encoded URL string, $str: to be encoded String return value: Returns the encoded string
Encoding specification: All non-alphanumeric characters except -_. in this string will be replaced with a percent sign (%) followed by two digits Hexadecimal numbers, spaces are encoded as plus signs ( )
After the commonly used characters are encoded, the encoded format is represented in brackets: ?(?), =(=), spaces ( ), % (%), &(&), \(\), (+)
2. urldecode(string $str): decode the encoded URL string, $str: the return value of the string to be decoded : Return the decoded string
Note: rawurlencode encoding rawurldecode decoding is exactly the same as the above urlencode urldecode. The principle and usage are exactly the same. The only difference: rawurlencode encodes spaces into
5.Base64 encoding encryption technology - two-way
1. base64_encode(string $data): Use base64 to encode data
2. base64_decode(string $data ,$strict=false): Decode data encoded using base64, $strict returns false if the input data exceeds the base64 alphabet
Summary: Roughly speaking, encryption technology can be divided into the following three types
1. One-way hash encryption
2. Symmetric hash encryption
3. Asymmetric hash encryption
Related recommendations:
php user password encryption algorithm analysis
php encryption and decryption method
The above is the detailed content of How to encrypt PHP code? Introduction to php encryption algorithm. For more information, please follow other related articles on the PHP Chinese website!