JS crypt and decrypt with crypto-js
JavaScript HTML
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
dist version May 15, 2016
example clean May 15, 2016
src grunt May 15, 2016
test clean May 15, 2016
.bowerrc initial import May 15, 2016
.gitignore example May 15, 2016
.jshintrc
.travis.yml karma May 15, 2016
Gruntfile.js
README.md clean May 15, 2016
bower.json version May 15, 2016
karma.conf.js initial import May 15, 2016
package.json version May 15, 2016

README.md

JS crypt and decrypt with crypto-js

Build Status

crypt-js wrapper

install node package

npm g-crypt

install bower package

bower install g-crypt

Example

Encrypt and decrypt socket.io comunications

The socket.io server

var io = require('socket.io')(3000),
    Crypt = require("g-crypt"),
    passphrase = 'fcf8afd67e96fa3366dd8eafec8bcace',
    crypter = Crypt(passphrase);

io.on('connection', function (socket) {
    socket.on('counter', function (data) {
        var decriptedData = crypter.decrypt(data);
        setTimeout(function () {
            console.log("counter status: " + decriptedData.id);
            decriptedData.id++;
            socket.emit('counter', crypter.encrypt(decriptedData));
        }, 1000);
    });
});

the HTTP client

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
Open console to see the messages

<script src="http://localhost:3000/socket.io/socket.io.js"></script>
<script src="assets/cryptojslib/rollups/aes.js"></script>
<script src="assets/g-crypt/src/Crypt.js"></script>
<script>
    var socket = io('http://localhost:3000/'),
        passphrase = 'fcf8afd67e96fa3366dd8eafec8bcace',
        crypter = Crypt(passphrase),
        id = 0;

    socket.on('connect', function () {
        console.log("connected! Let's start the counter with: " + id);
        socket.emit('counter', crypter.encrypt({id: id}));
    });

    socket.on('counter', function (data) {
        var decriptedData = crypter.decrypt(data);
        console.log("counter status: " + decriptedData.id);
        socket.emit('counter', crypter.encrypt({id: decriptedData.id}));
    });
</script>

</body>
</html>