LV. Mcrypt Encryption Functions

דוגמה 1 .

 
?php

 
$key

 
=

 
"

 
this

 
is

 
a

 
very

 
secret

 
key"

 
;

 
$input

 
=

 
"Let

 
us

 
meet

 
at

 
9

 
o'clock

 
at

 
the

 
secret

 
place

 
."

 
;

 
$encrypted_data

 
=

 
mcrypt_ecb

 
(MCRYPT_3DES

 
,

 
$key

 
,

 
$input

 
,

 
MCRYPT_ENCRYPT)

 
;

 
?



This example will give you the encrypted data as a string in $encrypted_data .

דוגמה 2 .

 
?php

 
$key

 
=

 
"

 
this

 
is

 
a

 
very

 
secret

 
key"

 
;

 
$input

 
=

 
"Let

 
us

 
meet

 
at

 
9

 
o'clock

 
at

 
the

 
secret

 
place

 
."

 
;

 
$td

 
=

 
mcrypt_module_open

 
('tripledes'

 
,

 
''

 
,

 
'ecb'

 
,

 
'')

 
;

 
$iv

 
=

 
mcrypt_create_iv

 
(mcrypt_enc_get_iv_size

 
($td)

 
,

 
MCRYPT_RAND)

 
;

 
mcrypt_generic_init

 
($td

 
,

 
$key

 
,

 
$iv)

 
;

 
$encrypted_data

 
=

 
mcrypt_generic

 
($td

 
,

 
$input)

 
;

 
mcrypt_generic_end

 
($td)

 
;

 
?



This example will give you the encrypted data as a string in $encrypted_data . For a full example see mcrypt_module_open() .

Installation

To use it , download libmcrypt-x.x.tar.gz from here To use it , download libmcrypt-x.x.tar.gz from here and follow the included installation instructions . You need to compile PHP with the --with-mcrypt parameter to enable this extension .

Resource types

This extension does not define any resource types .

תוכן העניינים:
mcrypt_cbc -- Encrypt/decrypt data in CBC mode
mcrypt_cfb -- Encrypt/decrypt data in CFB mode
mcrypt_create_iv -- Create an initialization vector (IV) from a random source
mcrypt_decrypt -- Decrypts crypttext with given parameters
mcrypt_ecb -- Encrypt/decrypt data in ECB mode
mcrypt_enc_get_algorithms_name -- Returns the name of the opened algorithm
mcrypt_enc_get_block_size -- Returns the blocksize of the opened algorithm
mcrypt_enc_get_iv_size -- Returns the size of the IV of the opened algorithm
mcrypt_enc_get_key_size -- Returns the maximum supported keysize of the opened mode
mcrypt_enc_get_modes_name -- Returns the name of the opened mode
mcrypt_enc_get_supported_key_sizes -- Returns an array with the supported keysizes of the opened algorithm
mcrypt_enc_is_block_algorithm -- Checks whether the algorithm of the opened mode is a block algorithm
mcrypt_enc_is_block_algorithm_mode -- Checks whether the encryption of the opened mode works on blocks
mcrypt_enc_is_block_mode -- Checks whether the opened mode outputs blocks
mcrypt_enc_self_test -- This function runs a self test on the opened module
mcrypt_encrypt -- Encrypts plaintext with given parameters
mcrypt_generic -- This function encrypts data
mcrypt_generic_deinit -- This function deinitializes an encryption module
mcrypt_generic_end -- This function terminates encryption
mcrypt_generic_init -- This function initializes all buffers needed for encryption
mcrypt_get_block_size -- Get the block size of the specified cipher
mcrypt_get_cipher_name -- Get the name of the specified cipher
mcrypt_get_iv_size -- Returns the size of the IV belonging to a specific cipher/mode combination
mcrypt_get_key_size -- Get the key size of the specified cipher
mcrypt_list_algorithms -- Get an array of all supported ciphers
mcrypt_list_modes -- Get an array of all supported modes
mcrypt_module_close -- Close the mcrypt module
mcrypt_module_get_algo_block_size -- Returns the blocksize of the specified algorithm
mcrypt_module_get_algo_key_size -- Returns the maximum supported keysize of the opened mode
mcrypt_module_get_supported_key_sizes -- Returns an array with the supported keysizes of the opened algorithm
mcrypt_module_is_block_algorithm -- This function checks whether the specified algorithm is a block algorithm
mcrypt_module_is_block_algorithm_mode -- This function returns if the the specified module is a block algorithm or not
mcrypt_module_is_block_mode -- This function returns if the the specified mode outputs blocks or not
mcrypt_module_open -- This function opens the module of the algorithm and the mode to be used
mcrypt_module_self_test -- This function runs a self test on the specified module
mcrypt_ofb -- Encrypt/decrypt data in OFB mode
mdecrypt_generic -- This function decrypts data