...
 
Commits (2)
......@@ -22,6 +22,8 @@ export declare class Common {
private static force_bytes(input);
private static force_java_bytes(input);
private static trimJavaBytes(input);
static crypto_box_easy(message: string | Uint8Array, nonce: Uint8Array, publicKey: any, privateKey: any): Uint8Array;
static crypto_box_open_easy(ciphertext: Uint8Array, nonce: Uint8Array, publicKey: Uint8Array, privateKey: Uint8Array): Uint8Array;
static crypto_secretbox_easy(message: string | Uint8Array, nonce: Uint8Array, key: Uint8Array): Uint8Array;
static crypto_secretbox_open_easy(ciphertext: Uint8Array, nonce: Uint8Array, key: Uint8Array): Uint8Array;
static crypto_box_seal(message: string | Uint8Array, publicKey: Uint8Array): Uint8Array;
......
......@@ -123,6 +123,46 @@ export class Common {
return (out as any);
}
public static crypto_box_easy(
message: string | Uint8Array,
nonce: Uint8Array,
publicKey: any,
privateKey: any
): Uint8Array {
let messageBytes = this.force_java_bytes(message);
let nonceBytes = this.force_java_bytes(nonce);
let publicKeyBytes = this.force_java_bytes(publicKey);
let PrivateKeyBytes = this.force_java_bytes(privateKey);
let ciphertext: JavaBytes = Array.create('byte', Sodium.crypto_box_macbytes() + messageBytes.length);
Sodium.crypto_box_easy(ciphertext, messageBytes, messageBytes.length, nonceBytes, publicKeyBytes, PrivateKeyBytes);
return this.javaByteArrayToUint8Array(ciphertext);
}
public static crypto_box_open_easy(
ciphertext: Uint8Array,
nonce: Uint8Array,
publicKey: Uint8Array,
privateKey: Uint8Array
): Uint8Array {
let ciphertextBytes = this.force_java_bytes(ciphertext);
let nonceBytes = this.force_java_bytes(nonce);
let publicKeyBytes = this.force_java_bytes(publicKey);
let privateKeyBytes = this.force_java_bytes(privateKey);
let decrypted: JavaBytes = Array.create('byte', Sodium.crypto_box_macbytes() + ciphertextBytes.length);
Sodium.crypto_box_open_easy(
decrypted,
ciphertextBytes,
ciphertextBytes.length,
nonceBytes,
publicKeyBytes,
privateKeyBytes,
);
decrypted = this.trimJavaBytes(decrypted);
return this.javaByteArrayToUint8Array(decrypted);
}
public static crypto_secretbox_easy(message: string | Uint8Array, nonce: Uint8Array, key: Uint8Array): Uint8Array {
let messageBytes = this.force_java_bytes(message);
......
{
"name": "nativescript-libsodium",
"version": "1.3.1",
"version": "1.3.3",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
......
{
"name": "nativescript-libsodium",
"version": "1.3.2",
"version": "1.3.3",
"description": "Use libsodium in Nativescript with libsodium.js like wrappers.",
"main": "libsodium",
"typings": "index.d.ts",
......