Base64 Encryption in Javascript and Decryption in PHP

jQuery :

var pass=document.getElementById(‘new_pwd’).value;

var base64 = window.btoa(pass);

return base64 to php file

PHP :

$decrypted = base64_decode($this->input->post(‘new_pwd’));
echo $decrypted;

Advertisements

Encrypt password on client side and Decrypt on server side using jquery and php

jQuery:
https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.2/rollups/aes.js
http://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/md5.js

function encrypt()
{
var key = CryptoJS.enc.Hex.parse(“0123456789abcdef0123456789abcdef”);
var iv = CryptoJS.enc.Hex.parse(“abcdef9876543210abcdef9876543210″);

var pass=document.getElementById(‘new_pwd’).value;
var hide=document.getElementById(‘hide’).value;
if(pass==””)
{
document.getElementById(‘err’).innerHTML=’Error:Password is missing’;
return false;
}
else
{
document.getElementById(“hide”).value = document.getElementById(“new_pwd”).value;
//var hash = CryptoJS.MD5(pass);

var hash = CryptoJS.AES.encrypt(pass, key, {iv:iv});

document.getElementById(‘new_pwd’).value=hash;
return true;
}
}

PHP:


$key = pack(“H*”, “0123456789abcdef0123456789abcdef”);
$iv = pack(“H*”, “abcdef9876543210abcdef9876543210”);
$encrypted = base64_decode($this->input->post(‘new_pwd’));
$shown = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $key, $encrypted, MCRYPT_MODE_CBC, $iv);
echo $shown;

window.open().focus()

window.open().focus()

Is used to bring the opened window to the top of the current page , even if you click back an parent page an again trying to open the same opened page.

In Firefox window.open() will open the page to top but when you back and forth from previous page it will hide in the background for solving this we can use .focus() to the window open method.