Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

mcrypt_generic_init(3) [php man page]

MCRYPT_GENERIC_INIT(3)							 1						    MCRYPT_GENERIC_INIT(3)

mcrypt_generic_init - This function initializes all buffers needed for encryption

SYNOPSIS
int mcrypt_generic_init (resource $td, string $key, string $iv) DESCRIPTION
You need to call this function before every call to mcrypt_generic(3) or mdecrypt_generic(3). PARAMETERS
o $td - The encryption descriptor. o $key - The maximum length of the key should be the one obtained by calling mcrypt_enc_get_key_size(3) and every value smaller than this is legal. o $iv - The IV should normally have the size of the algorithms block size, but you must obtain the size by calling mcrypt_enc_get_iv_size(3). IV is ignored in ECB. IV MUST exist in CFB, CBC, STREAM, nOFB and OFB modes. It needs to be random and unique (but not secret). The same IV must be used for encryption/decryption. If you do not want to use it you should set it to zeros, but this is not recommended. RETURN VALUES
The function returns a negative value on error: -3 when the key length was incorrect, -4 when there was a memory allocation problem and any other return value is an unknown error. If an error occurs a warning will be displayed accordingly. FALSE is returned if incorrect parameters were passed. SEE ALSO
mcrypt_module_open(3). PHP Documentation Group MCRYPT_GENERIC_INIT(3)

Check Out this Related Man Page

MCRYPT_GENERIC(3)							 1							 MCRYPT_GENERIC(3)

mcrypt_generic - This function encrypts data

SYNOPSIS
string mcrypt_generic (resource $td, string $data) DESCRIPTION
This function encrypts data. The data is padded with " " to make sure the length of the data is n * blocksize. This function returns the encrypted data. Note that the length of the returned string can in fact be longer than the input, due to the padding of the data. If you want to store the encrypted data in a database make sure to store the entire string as returned by mcrypt_generic, or the string will not entirely decrypt properly. If your original string is 10 characters long and the block size is 8 (use mcrypt_enc_get_block_size(3) to determine the blocksize), you would need at least 16 characters in your database field. Note the string returned by mdecrypt_generic(3) will be 16 characters as well...use rtrim($str, "") to remove the padding. If you are for example storing the data in a MySQL database remember that varchar fields automatically have trailing spaces removed during insertion. As encrypted data can end in a space (ASCII 32), the data will be damaged by this removal. Store data in a tinyblob/tinytext (or larger) field instead. PARAMETERS
o $td - The encryption descriptor. The encryption handle should always be initialized with mcrypt_generic_init(3) with a key and an IV before calling this function. Where the encryption is done, you should free the encryption buffers by calling mcrypt_generic_deinit(3). See mcrypt_module_open(3) for an example. o $data - The data to encrypt. RETURN VALUES
Returns the encrypted data. SEE ALSO
mdecrypt_generic(3), mcrypt_generic_init(3), mcrypt_generic_deinit(3). PHP Documentation Group MCRYPT_GENERIC(3)
Man Page