mirror of
https://github.com/moparisthebest/mail
synced 2025-02-26 07:41:48 -05:00
nacl-crypto cleanup
This commit is contained in:
parent
3f82fdf960
commit
0b37b40417
@ -43,7 +43,7 @@ var NaclCrypto = function(nacl, util) {
|
|||||||
* @param senderBoxSk [String] The sender's base64 encoded private key
|
* @param senderBoxSk [String] The sender's base64 encoded private key
|
||||||
* @return [Object] The base64 encoded ciphertext and nonce
|
* @return [Object] The base64 encoded ciphertext and nonce
|
||||||
*/
|
*/
|
||||||
this.asymmetricEncrypt = function(plaintext, nonce, recipientBoxPk, senderBoxSk) {
|
this.asymEncrypt = function(plaintext, nonce, recipientBoxPk, senderBoxSk) {
|
||||||
// convert to Uint8Array
|
// convert to Uint8Array
|
||||||
var ptBuf = nacl.encode_utf8(plaintext);
|
var ptBuf = nacl.encode_utf8(plaintext);
|
||||||
var recipientBoxPkBuf = nacl.encode_latin1(util.base642Str(recipientBoxPk));
|
var recipientBoxPkBuf = nacl.encode_latin1(util.base642Str(recipientBoxPk));
|
||||||
@ -65,7 +65,7 @@ var NaclCrypto = function(nacl, util) {
|
|||||||
* @param recipientBoxSk [String] The receiver's base64 encoded private key
|
* @param recipientBoxSk [String] The receiver's base64 encoded private key
|
||||||
* @return [String] The decrypted plaintext in UTF8
|
* @return [String] The decrypted plaintext in UTF8
|
||||||
*/
|
*/
|
||||||
this.asymmetricDecrypt = function(ciphertext, nonce, senderBoxPk, recipientBoxSk) {
|
this.asymDecrypt = function(ciphertext, nonce, senderBoxPk, recipientBoxSk) {
|
||||||
// convert to Uint8Array
|
// convert to Uint8Array
|
||||||
var ctBuf = nacl.encode_latin1(util.base642Str(ciphertext));
|
var ctBuf = nacl.encode_latin1(util.base642Str(ciphertext));
|
||||||
var nonceBuf = nacl.encode_latin1(util.base642Str(nonce));
|
var nonceBuf = nacl.encode_latin1(util.base642Str(nonce));
|
||||||
@ -86,7 +86,7 @@ var NaclCrypto = function(nacl, util) {
|
|||||||
* @param secretKey [String] The receiver's base64 encoded public key
|
* @param secretKey [String] The receiver's base64 encoded public key
|
||||||
* @return [Object] The base64 encoded ciphertext and nonce
|
* @return [Object] The base64 encoded ciphertext and nonce
|
||||||
*/
|
*/
|
||||||
this.symmetricEncrypt = function(plaintext, nonce, secretKey) {
|
this.symEncrypt = function(plaintext, nonce, secretKey) {
|
||||||
// convert to Uint8Array
|
// convert to Uint8Array
|
||||||
var ptBuf = nacl.encode_utf8(plaintext);
|
var ptBuf = nacl.encode_utf8(plaintext);
|
||||||
var secretKeyBuf = nacl.encode_latin1(util.base642Str(secretKey));
|
var secretKeyBuf = nacl.encode_latin1(util.base642Str(secretKey));
|
||||||
@ -106,7 +106,7 @@ var NaclCrypto = function(nacl, util) {
|
|||||||
* @param secretKey [String] The sender's base64 encoded public key
|
* @param secretKey [String] The sender's base64 encoded public key
|
||||||
* @return [String] The decrypted plaintext in UTF8
|
* @return [String] The decrypted plaintext in UTF8
|
||||||
*/
|
*/
|
||||||
this.symmetricDecrypt = function(ciphertext, nonce, secretKey) {
|
this.symDecrypt = function(ciphertext, nonce, secretKey) {
|
||||||
// convert to Uint8Array
|
// convert to Uint8Array
|
||||||
var ctBuf = nacl.encode_latin1(util.base642Str(ciphertext));
|
var ctBuf = nacl.encode_latin1(util.base642Str(ciphertext));
|
||||||
var nonceBuf = nacl.encode_latin1(util.base642Str(nonce));
|
var nonceBuf = nacl.encode_latin1(util.base642Str(nonce));
|
||||||
|
@ -37,11 +37,11 @@ test("Asymmetric En/Decrypt", 3, function() {
|
|||||||
var nonce = nacl_test.crypto.generateNonce();
|
var nonce = nacl_test.crypto.generateNonce();
|
||||||
ok(nonce, 'Nonce: ' + nonce);
|
ok(nonce, 'Nonce: ' + nonce);
|
||||||
// encrypt
|
// encrypt
|
||||||
var ct = nacl_test.crypto.asymmetricEncrypt(plaintext, nonce, nacl_test.recipientKeypair.boxPk, nacl_test.senderKeypair.boxSk);
|
var ct = nacl_test.crypto.asymEncrypt(plaintext, nonce, nacl_test.recipientKeypair.boxPk, nacl_test.senderKeypair.boxSk);
|
||||||
ok(ct, 'Ciphertext length: ' + ct.length);
|
ok(ct, 'Ciphertext length: ' + ct.length);
|
||||||
|
|
||||||
// decrypt
|
// decrypt
|
||||||
var decrypted = nacl_test.crypto.asymmetricDecrypt(ct, nonce, nacl_test.senderKeypair.boxPk, nacl_test.recipientKeypair.boxSk);
|
var decrypted = nacl_test.crypto.asymDecrypt(ct, nonce, nacl_test.senderKeypair.boxPk, nacl_test.recipientKeypair.boxSk);
|
||||||
equal(decrypted, plaintext, 'Decryption correct: ' + decrypted);
|
equal(decrypted, plaintext, 'Decryption correct: ' + decrypted);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -51,11 +51,11 @@ test("Symmetric En/Decrypt", 3, function() {
|
|||||||
var nonce = nacl_test.crypto.generateNonce();
|
var nonce = nacl_test.crypto.generateNonce();
|
||||||
ok(nonce, 'Nonce: ' + nonce);
|
ok(nonce, 'Nonce: ' + nonce);
|
||||||
// encrypt
|
// encrypt
|
||||||
var ct = nacl_test.crypto.symmetricEncrypt(plaintext, nonce, nacl_test.senderKeypair.boxSk);
|
var ct = nacl_test.crypto.symEncrypt(plaintext, nonce, nacl_test.senderKeypair.boxSk);
|
||||||
ok(ct, 'Ciphertext length: ' + ct.length);
|
ok(ct, 'Ciphertext length: ' + ct.length);
|
||||||
|
|
||||||
// decrypt
|
// decrypt
|
||||||
var decrypted = nacl_test.crypto.symmetricDecrypt(ct, nonce, nacl_test.senderKeypair.boxSk);
|
var decrypted = nacl_test.crypto.symDecrypt(ct, nonce, nacl_test.senderKeypair.boxSk);
|
||||||
equal(decrypted, plaintext, 'Decryption correct: ' + decrypted);
|
equal(decrypted, plaintext, 'Decryption correct: ' + decrypted);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user