Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added ezcrypto repo as submodule

  • Loading branch information...
commit 3198b3898497c58af38c9c17c149c217b05ac9e7 1 parent c2c92f1
@tjgillies tjgillies authored
View
3  .gitmodules
@@ -0,0 +1,3 @@
+[submodule "ezcrypto-js"]
+ path = ezcrypto-js
+ url = git://github.com/tjgillies/ezcrypto-js.git
1  ezcrypto-js
@@ -0,0 +1 @@
+Subproject commit 1342d048e3bcc264b1207cc73f3912748a17ed39
View
16 node.js/message.js
@@ -1,13 +1,14 @@
var dgram = require('dgram');
var message = new Buffer(JSON.stringify({"+end":"38666817e1b38470644e004b9356c1622368fa57"}));
var socket = dgram.createSocket("udp4");
-var crypto = require('crypto');
+var ezcrypto = require('../ezcrypto-js/ezcrypto.js').ezcrypto;
+
+
socket.sendData = function(message){ console.log(message.toString()); this.send(message, 0, message.length, 42424, "telehash.org"); }
socket.on("message", function(data, rinfo){
console.log(data.toString());
- console.log("message");
telex = JSON.parse(data.toString());
//console.log("TELEX: " + JSON.stringify(telex));
if (telex["_ring"]){
@@ -22,12 +23,13 @@ socket.on("message", function(data, rinfo){
var key = telex["+key"];
//console.log(key);
var signature = telex["+sig"];
- var verifier = crypto.createVerify('RSA-SHA1');
- verifier.update(message);
+ //var verifier = crypto.createVerify('RSA-SHA1');
+ //verifier.update(message);
+ var test = ezcrypto.verify(message, signature, key)
//console.log(message);
- var bool =verifier.verify(key, signature, signature_format='hex');
+ //var bool =verifier.verify(key, signature, signature_format='hex');
//console.log(bool);
- if (bool){
+ if (test){
console.log("Key validates");
} else {
console.log("Key doesn't validate");
@@ -38,8 +40,6 @@ socket.on("message", function(data, rinfo){
socket.on("listening", function(){
console.log("Now listening");
- //othersocket = dgram.createSocket("udp4");
- //othersocket.send(message, 0, message.length, 42424, "telehash.org");
socket.send(message, 0, message.length, 42424, "telehash.org");
});
View
22 node.js/send.js
@@ -1,17 +1,23 @@
var dgram = require('dgram');
var crypto = require('crypto');
var fs = require('fs');
+var ezcrypto = require('../ezcrypto-js/ezcrypto.js').ezcrypto;
+var keys = ezcrypto.generateKey();
+
+
+//var keyPem = fs.readFileSync("mykey.pem", 'ascii');
+//var pubKey = fs.readFileSync("mycert.pem", 'ascii');
+//var cred = crypto.createCredentials({key:keyPem});
+//var key = cred.key;
-var keyPem = fs.readFileSync("mykey.pem", 'ascii');
-var pubKey = fs.readFileSync("mycert.pem", 'ascii');
-var cred = crypto.createCredentials({key:keyPem});
-var key = cred.key;
var socket = dgram.createSocket("udp4");
-var signer = crypto.createSign('RSA-SHA1');
+//var signer = crypto.createSign('RSA-SHA1');
var msg = "I like cheese";
-signer.update(msg);
-var signature = signer.sign(keyPem, output_format='hex');
-var json = {"+key":pubKey, "_hop":1,"+end":"8bf1cce916417d16b7554135b6b075fb16dd26ce","_to":"208.68.163.247:42424", "+sig":signature, "+message":msg};
+//signer.update(msg);
+//var signature = signer.sign(keyPem, output_format='hex');
+var hash = ezcrypto.hash(msg);
+var signature = ezcrypto.sign(hash, keys.public, keys.private);
+var json = {"+key":keys.public, "_hop":1,"+end":"8bf1cce916417d16b7554135b6b075fb16dd26ce","_to":"208.68.163.247:42424", "+sig":signature, "+message":msg};
var message = new Buffer(JSON.stringify(json));
console.log(message.toString());
Please sign in to comment.
Something went wrong with that request. Please try again.