mirror of
https://github.com/fluencelabs/js-libp2p-noise
synced 2025-07-31 02:42:13 +00:00
Test encryption and decryption
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { expect, assert } from "chai";
|
||||
import { Buffer } from 'buffer';
|
||||
import { ed25519 } from 'bcrypto';
|
||||
import { ed25519, AEAD } from 'bcrypto';
|
||||
|
||||
import { XXHandshake, KeyPair } from "../src/xx";
|
||||
import { loadPayloadProto, generateEd25519Keys } from "./utils";
|
||||
@@ -108,4 +108,15 @@ describe("Index", () => {
|
||||
await doHandshake(xx);
|
||||
});
|
||||
|
||||
it("Test symmetric encrypt and decrypt", async () => {
|
||||
const xx = new XXHandshake();
|
||||
const { nsInit, nsResp } = await doHandshake(xx);
|
||||
const ad = Buffer.from("authenticated");
|
||||
const message = Buffer.from("HelloCrypto");
|
||||
|
||||
xx.encryptWithAd(nsInit.cs1, ad, message);
|
||||
const decrypted = xx.decryptWithAd(nsResp.cs1, ad, message);
|
||||
|
||||
assert(Buffer.from("HelloCrypto").equals(decrypted), "Decrypted text buffer not equal to plaintext buffer");
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user