mirror of
https://github.com/moparisthebest/mail
synced 2024-11-25 18:32:20 -05:00
finished nacl impl and tests
This commit is contained in:
parent
21aad0afb2
commit
2d37e8f3f7
@ -6,17 +6,22 @@ var NaclCrypto = function(util) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates a baes64 encoded keypair for use with NaCl
|
* Generates a baes64 encoded keypair for use with NaCl
|
||||||
|
* @param seed [String] A base64 encoded (pseudo) random seed e.g. PBKDF2
|
||||||
*/
|
*/
|
||||||
this.generateKeypair = function(seed) {
|
this.generateKeypair = function(seed) {
|
||||||
|
var keys;
|
||||||
|
|
||||||
if (seed) {
|
if (seed) {
|
||||||
return null; // TODO: generate from PBKDF2
|
var seedBuf = nacl.encode_latin1(util.base642Str(seed));
|
||||||
|
keys = nacl.crypto_box_keypair_from_seed(seedBuf);
|
||||||
} else {
|
} else {
|
||||||
var keys = nacl.crypto_box_keypair();
|
keys = nacl.crypto_box_keypair();
|
||||||
return {
|
|
||||||
boxPk: util.str2Base64(nacl.decode_latin1(keys.boxPk)),
|
|
||||||
boxSk: util.str2Base64(nacl.decode_latin1(keys.boxSk))
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
boxPk: util.str2Base64(nacl.decode_latin1(keys.boxPk)),
|
||||||
|
boxSk: util.str2Base64(nacl.decode_latin1(keys.boxSk))
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -6,21 +6,22 @@ var nacl_test = {
|
|||||||
|
|
||||||
test("Init", 1, function() {
|
test("Init", 1, function() {
|
||||||
// init dependencies
|
// init dependencies
|
||||||
var util = new app.crypto.Util(window, uuid);
|
nacl_test.util = new app.crypto.Util(window, uuid);
|
||||||
ok(util, 'Util');
|
ok(nacl_test.util, 'Util');
|
||||||
// generate test data
|
// generate test data
|
||||||
nacl_test.test_message = new TestData().generateBigString(1000);
|
nacl_test.test_message = new TestData().generateBigString(1000);
|
||||||
nacl_test.crypto = new app.crypto.NaclCrypto(util);
|
nacl_test.crypto = new app.crypto.NaclCrypto(nacl_test.util);
|
||||||
});
|
});
|
||||||
|
|
||||||
// test("Generate Keypair from seed", 2, function() {
|
test("Generate Keypair from seed", 1, function() {
|
||||||
// // generate keypair from seed
|
// generate keypair from seed
|
||||||
// var keys = nacl_test.crypto.generateKeypair();
|
var seed = nacl_test.util.random(128);
|
||||||
// ok(keys.boxSk && keys.boxPk, "Keypair: " + JSON.stringify(keys));
|
var keys = nacl_test.crypto.generateKeypair(seed);
|
||||||
// });
|
ok(keys.boxSk && keys.boxPk, "Keypair: " + JSON.stringify(keys));
|
||||||
|
});
|
||||||
|
|
||||||
test("Generate Keypair", 2, function() {
|
test("Generate Keypair", 2, function() {
|
||||||
// generate keypair from seed
|
// generate keypair
|
||||||
var senderKeypair = nacl_test.crypto.generateKeypair();
|
var senderKeypair = nacl_test.crypto.generateKeypair();
|
||||||
ok(senderKeypair.boxSk && senderKeypair.boxPk, "Sender keypair: " + JSON.stringify(senderKeypair));
|
ok(senderKeypair.boxSk && senderKeypair.boxPk, "Sender keypair: " + JSON.stringify(senderKeypair));
|
||||||
var recipientKeypair = nacl_test.crypto.generateKeypair();
|
var recipientKeypair = nacl_test.crypto.generateKeypair();
|
||||||
|
Loading…
Reference in New Issue
Block a user