Htaccess    html   Php    javascript   Asp   css    maths  Past Questions  Practice Tests Online

mcrypt encrypt function syntax tag tutorial 2013





Alert! Connect with 10,000 Chating Online. Join Now

Php mcrypt encrypt () function

Write your php code

 
<?php ?>

Php Result


Your code below



(PHP 4 >= 4.0.2, PHP 5)

mcrypt_encrypt -- Encrypts plaintext with given parameters

Syntax

string mcrypt_encrypt ( string cipher, string key, string data, string mode [, string iv] )

mcrypt_encrypt() encrypts the data and returns the encrypted data.

Cipher is one of the MCRYPT_ciphername constants of the name of the algorithm as string.

Key is the key with which the data will be encrypted. If it's smaller that the required keysize, it is padded with '\0'. It is better not to use ASCII strings for keys. It is recommended to use the mhash functions to create a key from a string.

Data is the data that will be encrypted with the given cipher and mode. If the size of the data is not n * blocksize, the data will be padded with '\0'. The returned crypttext can be larger that the size of the data that is given by data.

Mode is one of the MCRYPT_MODE_modename constants of one of "ecb", "cbc", "cfb", "ofb", "nofb" or "stream".

The IV parameter is used for the initialisation in CBC, CFB, OFB modes, and in some algorithms in STREAM mode. If you do not supply an IV, while it is needed for an algorithm, the function issues a warning and uses an IV with all bytes set to '\0'.

Example 1. mcrypt_encrypt() Example

<?php
    $iv_size
= mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
    
$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
    
$key = "This is a very secret key";
    
$text = "Meet me at 11 o'clock behind the monument.";
    echo
strlen($text) . "\n";

    
$crypttext = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $text, MCRYPT_MODE_ECB, $iv);
    echo
strlen($crypttext) . "\n";
?>

The above example will output:

42
64

See also mcrypt_module_open() for a more advanced API and an example.

Php mcrypt encrypt Function syntax tag

mcrypt encrypt php code on this is provided for your study purpose, it will guide you to know how create and design a website using php. use it to practice and train your self online



Php mcrypt encrypt syntax tutorial

php tutorial guide and code design are for easy learning and programming. The code practice section provided at the top is for practising of this syntax. Use the code section up to practice your php programming online. Learning php is very easy, all you need is to use the examples on this site and practice them to perfect your skills.


Function index

Variables

Expressions

Operators

Control-Structures

Cookies

Array

Date & Time

Directory function

File

Image

Operators

Form data handling

Mathematics operators

Mail

Php Mysql

Network Functions

Strings

php tutorial guides,functions, classes, code examples and tags for creating simple dynamic site to mysql database driven sites
 
 
Htaccess    html   Php    javascript   Asp   css    maths  Past Questions  Practice Tests Online