Commit 2e520fc6 authored by David Burke's avatar David Burke

encrypt and decrypt test now passes

parent 13c0e90b
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var nativescript_libsodium_1 = require("nativescript-libsodium");
describe("libsodium nativescript wrapper", function () {
it("can generate a keypair", function () {
var keypair = nativescript_libsodium_1.Libsodium.crypto_box_keypair();
expect(keypair.privateKey).toBeDefined();
expect(keypair.publicKey).toBeDefined();
});
it("can run crypto_pwhash", function () {
var salt = new Uint8Array([88, 240, 185, 66, 195, 101, 160, 138, 137, 78, 1, 2, 3, 4, 5, 6]);
var hash = nativescript_libsodium_1.Libsodium.crypto_pwhash(nativescript_libsodium_1.Libsodium.crypto_box_SEEDBYTES, "hunter2", salt, nativescript_libsodium_1.Libsodium.crypto_pwhash_OPSLIMIT_INTERACTIVE, nativescript_libsodium_1.Libsodium.crypto_pwhash_MEMLIMIT_INTERACTIVE, nativescript_libsodium_1.Libsodium.crypto_pwhash_ALG_DEFAULT);
expect(hash[0]).toEqual(49);
});
});
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdHMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyJ0ZXN0cy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLGlFQUFtRDtBQUVuRCxRQUFRLENBQUMsZ0NBQWdDLEVBQUU7SUFDdkMsRUFBRSxDQUFDLHdCQUF3QixFQUFFO1FBQ3pCLElBQUksT0FBTyxHQUFHLGtDQUFTLENBQUMsa0JBQWtCLEVBQUUsQ0FBQztRQUM3QyxNQUFNLENBQUMsT0FBTyxDQUFDLFVBQVUsQ0FBQyxDQUFDLFdBQVcsRUFBRSxDQUFDO1FBQ3pDLE1BQU0sQ0FBQyxPQUFPLENBQUMsU0FBUyxDQUFDLENBQUMsV0FBVyxFQUFFLENBQUM7SUFDNUMsQ0FBQyxDQUFDLENBQUM7SUFFSCxFQUFFLENBQUMsdUJBQXVCLEVBQUU7U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Fpci5wdWJsaWNLZXkpLnRvQmVEZWZpbmVkKCk7XG4gICAgfSk7XG5cbiAgICBpdChcImNhbiBydW4gY3J5cHRvX3B3aGFzaFwiLCBmdW5jdGlvbigpIHtcbiAgICAgICAgbGV0IHNhbHQgPSBuZXcgVWludDhBcnJheShbIDg4LCAyNDAsIDE4NSwgNjYsIDE5NSwgMTAxLCAxNjAsIDEzOCwgMTM3LCA3OCwgMSwgMiwgMywgNCwgNSwgNl0pO1xuICAgICAgICBsZXQgaGFzaCA9IExpYnNvZGl1bS5jcnlwdG9fcHdoYXNoKFxuICAgICAgICAgICAgTGlic29kaXVtLmNyeXB0b19ib3hfU0VFREJZVEVTLFxuICAgICAgICAgICAgXCJodW50ZXIyXCIsXG4gICAgICAgICAgICBzYWx0LFxuICAgICAgICAgICAgTGlic29kaXVtLmNyeXB0b19wd2hhc2hfT1BTTElNSVRfSU5URVJBQ1RJVkUsXG4gICAgICAgICAgICBMaWJzb2RpdW0uY3J5cHRvX3B3aGFzaF9NRU1MSU1JVF9JTlRFUkFDVElWRSxcbiAgICAgICAgICAgIExpYnNvZGl1bS5jcnlwdG9fcHdoYXNoX0FMR19ERUZBVUxULFxuICAgICAgICApO1xuICAgICAgICBleHBlY3QoaGFzaFswXSkudG9FcXVhbCg0OSk7XG4gICAgfSk7XG59KTtcbiJdfQ==
\ No newline at end of file
import { Libsodium } from "nativescript-libsodium";
import { TextDecoder } from "text-encoding";
describe("libsodium nativescript wrapper", function() {
it("can generate a keypair", function() {
......@@ -19,4 +20,14 @@ describe("libsodium nativescript wrapper", function() {
);
expect(hash[0]).toEqual(49);
});
it("can run crypto_secretbox_easy and crypto_secretbox_open_easy", function() {
let secretMessage = 'hello';
let nonce = Libsodium.randombytes_buf(Libsodium.crypto_secretbox_NONCEBYTES);
let key = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5]);
let ciphertext = Libsodium.crypto_secretbox_easy(secretMessage, nonce, key);
let decrypted = Libsodium.crypto_secretbox_open_easy(ciphertext, nonce, key);
let decryptedString = new TextDecoder('utf-8').decode(decrypted);
expect(decryptedString).toEqual(secretMessage);
});
});
......@@ -2,7 +2,7 @@ import { Observable } from 'tns-core-modules/data/observable';
import * as app from 'tns-core-modules/application';
import * as dialogs from 'tns-core-modules/ui/dialogs';
import { TextEncoder, TextDecoder, Buffer } from "text-encoding";
import { TextEncoder, TextDecoder } from "text-encoding";
const Random = org.libsodium.jni.crypto.Random;
const SodiumConstants = org.libsodium.jni.SodiumConstants;
......@@ -231,9 +231,9 @@ export class Common {
);
msg += `The hash is ${hash}\n`;
let secretMessage = 'helloo';
let nonce = Buffer.from(this.randombytes_buf(this.crypto_secretbox_NONCEBYTES));
let key = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5]);
let secretMessage = 'hello';
let nonce = this.randombytes_buf(this.crypto_secretbox_NONCEBYTES);
let key = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5]);
let ciphertext = this.crypto_secretbox_easy(secretMessage, nonce, key);
let decrypted = this.crypto_secretbox_open_easy(ciphertext, nonce, key);
let decryptedString = new TextDecoder('utf-8').decode(decrypted);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment