initial commit

This commit is contained in:
cupcakearmy
2019-03-30 20:50:04 +01:00
commit c1e4f4b1aa
10 changed files with 536 additions and 0 deletions

64
test/main.js Normal file
View File

@@ -0,0 +1,64 @@
const { describe, it } = require('mocha')
const a = require('assert')
const { RSA, AES } = require('../').default
describe('Asymmetric', () => {
describe('RSA', () => {
it('Encrypt and Decrypt small string', async () => {
const pair = await RSA.gen(2 ** 10)
const text = `some small string`
const e = RSA.encrypt(text, pair.pub)
const d = RSA.decrypt(e, pair.prv)
a.strictEqual(text, d)
})
})
})
describe('Symmetric', () => {
const keyLong = `yruyLaCAbcfJD9DKk3Ef6zuSFMPatwbg63ayPHVDSSxAePqtYxmd7N5BX2ShCgaG`
const keyShort = `simple`
const dataShort = `a sentence`
const dataLong = `Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.`
describe('AES', () => {
describe('Default', () => {
it('Short', () => {
const e = AES.encrypt(dataShort, keyShort)
const d = AES.decrypt(e, keyShort)
a.strictEqual(dataShort, d)
})
it('Long', () => {
const e = AES.encrypt(dataLong, keyLong)
const d = AES.decrypt(e, keyLong)
a.strictEqual(dataLong, d)
})
})
describe('GCM', () => {
it('128', () => {
const e = AES.encrypt(dataShort, keyShort, AES.Ciphers.AES_128_GCM)
const d = AES.decrypt(e, keyShort)
a.strictEqual(dataShort, d)
})
it('192', () => {
const e = AES.encrypt(dataShort, keyShort, AES.Ciphers.AES_192_GCM)
const d = AES.decrypt(e, keyShort)
a.strictEqual(dataShort, d)
})
it('256', () => {
const e = AES.encrypt(dataShort, keyShort, AES.Ciphers.AES_256_GCM)
const d = AES.decrypt(e, keyShort)
a.strictEqual(dataShort, d)
})
})
})
})