Crypt Function PHP Source Code

Encrypting data is one of the security features that is present in any programming language.

This is the first part of the encryption process that iwantsourcecodes will provide to you:

Here is the first one:

The crypt() function returns a string encrypted using DES, Blowfish, or MD5 algorithms.

This function behaves different on different operating systems, some operating systems supports more than one type of encryption. PHP checks what algorithms are available and what algorithms to use when it is installed.

The exact algorithm depends on the format and length of the salt parameter. Salts help make the encryption more secure by increasing the number of encrypted strings that can be generated for one specific string with one specific encryption method.

There are some constants that are used together with the crypt() function. The value of these constants are set by PHP when it is installed.


[CRYPT_SALT_LENGTH] – The length of the default encryption. With standard DES encryption, the length is 2
[CRYPT_STD_DES] – Value is 1 if the standard DES algorithm is supported, 0 otherwise. The Standard DES-based encryption has a two character salt
[CRYPT_EXT_DES] – Value is1 if the extended DES algorithm is supported, 0 otherwise. The Extended DES encryption has a nine character salt
[CRYPT_MD5] – Value is 1 if the MD5 algorithm is supported, 0 otherwise. The MD5 encryption has a 12 character salt starting with $1$
[CRYPT_BLOWFISH] – Value is 1 if the Blowfish algorithm is supported, 0 otherwise. The Blowfish encryption has a 16 character salt starting with $2$ or $2a$


str – Specifies the string to be encoded
salt – A string used to increase the number of characters encoded, to make the encoding more secure. If the salt argument is not provided, one will be randomly generated by PHP each time you call this function.







View all contributions by

0 comments… add one