mirror of
https://github.com/darkwire/darkwire.io.git
synced 2025-07-21 12:36:28 +00:00
Encrypt and decrypt messages
This commit is contained in:
parent
a71ebc44d4
commit
9e9b4651ba
@ -64,10 +64,18 @@ $(function() {
|
|||||||
message: message
|
message: message
|
||||||
});
|
});
|
||||||
// tell server to execute 'new message' and send along one parameter
|
// tell server to execute 'new message' and send along one parameter
|
||||||
socket.emit('new message', message);
|
socket.emit('new message', encrypt(message));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function encrypt(text) {
|
||||||
|
return CryptoJS.AES.encrypt(text, roomId).toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
function decrypt(text) {
|
||||||
|
return CryptoJS.AES.decrypt(text, roomId).toString(CryptoJS.enc.Utf8);
|
||||||
|
}
|
||||||
|
|
||||||
// Log a message
|
// Log a message
|
||||||
function log (message, options) {
|
function log (message, options) {
|
||||||
var $el = $('<li>').addClass('log').text(message);
|
var $el = $('<li>').addClass('log').text(message);
|
||||||
@ -236,6 +244,7 @@ $(function() {
|
|||||||
|
|
||||||
// Whenever the server emits 'new message', update the chat body
|
// Whenever the server emits 'new message', update the chat body
|
||||||
socket.on('new message', function (data) {
|
socket.on('new message', function (data) {
|
||||||
|
data.message = decrypt(data.message);
|
||||||
addChatMessage(data);
|
addChatMessage(data);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
|
|
||||||
<script src="https://code.jquery.com/jquery-1.10.2.min.js"></script>
|
<script src="https://code.jquery.com/jquery-1.10.2.min.js"></script>
|
||||||
<script src="https://cdn.socket.io/socket.io-1.4.3.js"></script>
|
<script src="https://cdn.socket.io/socket.io-1.4.3.js"></script>
|
||||||
|
<script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/aes.js"></script>
|
||||||
<script src="/main.js"></script>
|
<script src="/main.js"></script>
|
||||||
<script>
|
<script>
|
||||||
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
|
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
|
||||||
|
Loading…
x
Reference in New Issue
Block a user