mirror of
https://github.com/darkwire/darkwire.io.git
synced 2025-07-21 04:26:47 +00:00
Encrypt and decrypt messages
This commit is contained in:
parent
a71ebc44d4
commit
9e9b4651ba
@ -64,10 +64,18 @@ $(function() {
|
||||
message: message
|
||||
});
|
||||
// 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
|
||||
function log (message, options) {
|
||||
var $el = $('<li>').addClass('log').text(message);
|
||||
@ -236,6 +244,7 @@ $(function() {
|
||||
|
||||
// Whenever the server emits 'new message', update the chat body
|
||||
socket.on('new message', function (data) {
|
||||
data.message = decrypt(data.message);
|
||||
addChatMessage(data);
|
||||
});
|
||||
|
||||
|
@ -20,6 +20,7 @@
|
||||
|
||||
<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="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/aes.js"></script>
|
||||
<script src="/main.js"></script>
|
||||
<script>
|
||||
(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