This tutorial help to encrypt and decrypt string using cryptojs and php.
Cryptojs is very popular library which is used to convert string into encrypted text and vise versa.
I am using below files for decrypt string in php
Angular application – Angularjs application convert string and send to php application for decrypt data.
index.php – This file responsible to decrypt string using
mcrypt_decrypt and display data.
We are using cryptojs Hex method to encode
iv in angularjs application. I am using below key and iv,
- key : 0123456789abcdef0123456789abcdef
- iv : abcdef9876543210abcdef9876543210
- Encrypted string : MwOfGGCYPBEpQ0ImKQsgyA==
Above salt string is puplic key which is available only both party server and front-end side.
Decrypt String in PHP using Cryptojs and AES
$key = pack("H*", "0123456789abcdef0123456789abcdef");
$iv = pack("H*", "abcdef9876543210abcdef9876543210");
$encrypted = base64_decode('MwOfGGCYPBEpQ0ImKQsgyA==');
$decrypt_string = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $key, $encrypted, MCRYPT_MODE_CBC, $iv);
I am using
mcrypt_decrypt() method for decrypt data and
MCRYPT_RIJNDAEL_128 cipher key.
This php tutorial help for basic encryption/decryption string using AES and PHP.You are free to use and customised this code.
You can download source code and Demo from below link.