mirror of
https://github.com/moparisthebest/mail
synced 2025-01-30 22:50:17 -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
|
||||
* @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
|
||||
var ptBuf = nacl.encode_utf8(plaintext);
|
||||
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
|
||||
* @return [String] The decrypted plaintext in UTF8
|
||||
*/
|
||||
this.asymmetricDecrypt = function(ciphertext, nonce, senderBoxPk, recipientBoxSk) {
|
||||
this.asymDecrypt = function(ciphertext, nonce, senderBoxPk, recipientBoxSk) {
|
||||
// convert to Uint8Array
|
||||
var ctBuf = nacl.encode_latin1(util.base642Str(ciphertext));
|
||||
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
|
||||
* @return [Object] The base64 encoded ciphertext and nonce
|
||||
*/
|
||||
this.symmetricEncrypt = function(plaintext, nonce, secretKey) {
|
||||
this.symEncrypt = function(plaintext, nonce, secretKey) {
|
||||
// convert to Uint8Array
|
||||
var ptBuf = nacl.encode_utf8(plaintext);
|
||||
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
|
||||
* @return [String] The decrypted plaintext in UTF8
|
||||
*/
|
||||
this.symmetricDecrypt = function(ciphertext, nonce, secretKey) {
|
||||
this.symDecrypt = function(ciphertext, nonce, secretKey) {
|
||||
// convert to Uint8Array
|
||||
var ctBuf = nacl.encode_latin1(util.base642Str(ciphertext));
|
||||
var nonceBuf = nacl.encode_latin1(util.base642Str(nonce));
|
||||
|
@ -37,11 +37,11 @@ test("Asymmetric En/Decrypt", 3, function() {
|
||||
var nonce = nacl_test.crypto.generateNonce();
|
||||
ok(nonce, 'Nonce: ' + nonce);
|
||||
// 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);
|
||||
|
||||
// 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);
|
||||
});
|
||||
|
||||
@ -51,11 +51,11 @@ test("Symmetric En/Decrypt", 3, function() {
|
||||
var nonce = nacl_test.crypto.generateNonce();
|
||||
ok(nonce, 'Nonce: ' + nonce);
|
||||
// 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);
|
||||
|
||||
// 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);
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user