Total Pageviews

Wednesday, December 17, 2014

PHP Encryption and Decryption by yourself

By Alpesh Vasan   Posted at  8:51 PM   No comments

Please test with yourself and like us if you are happy with this code ....


<?php

$key = 'Your own Key';
$string = 'Your String'; // Please do not use spaces.

$encrypted = base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, md5($key), $string, MCRYPT_MODE_CBC, md5(md5($key))));

$decrypted = rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, md5($key), base64_decode($encrypted), MCRYPT_MODE_CBC, md5(md5($key))), "\0");

echo 'Encrypted:' . "\n";
var_dump($encrypted);

echo "\n";

echo 'Decrypted:' . "\n";
var_dump($decrypted); // spaces are preserved

?>

Output : 

Origional : 'My String'

Encrypted:
string 'X7zPEx/hl2aMvBrK2+V3XJtqvQssSiYUQWTFyHlbjmQ=' (length=44)

Decrypted:
string 'My String' (length=9)

About the Author

Nulla sagittis convallis arcu. Sed sed nunc. Curabitur consequat. Quisque metus enim, venenatis fermentum, mollis in, porta et, nibh. Duis vulputate elit in elit. Mauris dictum libero id justo.
View all posts by: BT9

0 comments:

Please Rate this article

Back to top ↑
Connect with Us

    My Global Talks. Powered by Blogger.

What they says

© 2013 My Global Talks. WP Mythemeshop Converted by Bloggertheme9
Blogger templates. Proudly Powered by Blogger.