Giter VIP home page Giter VIP logo

crypto-js-and-php's Introduction

Cryptojs And PHP

This is a demo of sending encrypted data using crypto js and php

Why to use this method

To prevent Man-in-the-middle (mitm) attacks. Maximum cyber attacks occurs mitm attacks. It means the attcker can seen (intercept) your data before the server receives it from your browser. What if the data we send is already encrypted on the browser itself and send it to server. It is where thre crypto-to-php method works.

How to use it

Just enrypt the data using the method below:

CryptoJS.AES.encrypt(JSON.stringify(dataValue), TheSecret, {format: CryptoJSAesJson}).toString(); dataValue is your input value the TheSecret is your secret key. You can use your custom random genrated secret key, I have used time() for demo purpose. You can use https://github.com/deepaksingh1984/secureKey-in-php for your custom secret key encyption and decryption.

The method I used to acheive the purpose (just for demo purpose)

var dt = new Date();
var TheSecret = "";
$(document).ready(function(e) {
    $.ajax({
		url:'libs/php/get_random_key.php',
		type:'POST',
		data:"dts="+dt.getTime(),
		success: function(responseAjx){
			TheSecret = responseAjx;
			console.log(TheSecret);
		}
	});
});
$('button[name="sub"]').click(function(e) {
    var dataValue = $('input[name="data"]').val();
	var enData = CryptoJS.AES.encrypt(JSON.stringify(dataValue), TheSecret, {format: CryptoJSAesJson}).toString();
	$.ajax({
		url:'libs/php/decrypt.php',
		type:'POST',
		data:'crypt='+enData,
		success: function(cryptResponse){
			console.log(cryptResponse);
		}
	});
	
});

crypto-js-and-php's People

Contributors

deepaksingh1984 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.