Be8 uses a Elliptic Curve Diffie-Hellman 384 bit prime curve encryption to ensure safe e2ee communications.
The constructer takes one parameter the accID. In case of no id passed it throws an error. ID has to be a string that is a number.
const be8 = new Be8('1');
Checks if the object already generated keys and if they are stored. Returns a boolean.
be8.hasGeneratedKeys();
Return the accID.
be8.getAccID();
Takes an array of public key accid key pair values and calls addPublicKey for every pair.
const publicKeys = [{
accID: '',
publicKey: {
crv: 'P-384'
ext: 'true'
key_ops: ['deriveKey', 'deriveBits']
kty: 'EC'
x: 'A8QYrJJeE5iEshV3ycX2DNvgltSq9NHQypmkDybLHII'
y: 'IxbSJxIfvjuBvyTlNt_RToCgYzqvBHsIvWVB8bW-EFs'
}
}];
be8.addPublicKeys(publicKeys);
Adds an accID publicKey pair value to a private map.
const publicKey = {
accID: '10101',
publicKey: {
crv: 'P-384'
ext: 'true'
key_ops: ['deriveKey', 'deriveBits']
kty: 'EC'
x: 'A8QYrJJeE5iEshV3ycX2DNvgltSq9NHQypmkDybLHII'
y: 'IxbSJxIfvjuBvyTlNt_RToCgYzqvBHsIvWVB8bW-EFs'
}
};
be8.addPublicKey(publicKey);
Group keys are stored seperately from the other keys.
be8.addGroupKey('g10300', {});
Returns freshly generated private and public keys. Automatically stores the keys in the localstorage.
const [publicKey, privateKey] = await be8.generatePrivAndPubKey();
Generates a group key and stores it in a private map.
const [publicKey, privateKey] = await be8.generateGroupKeys();
Generates a derived key out of the public and private key.
const privateKey = {};
const publicKey = {};
const derivedKey = await be8.getDerivedKey(publicKey, privateKey);
After creating a derivedKey we can start to encrypt text messages. encryptText returns a cipherText and a iv (Initialization vector).
const text = 'Hello World';
const derivedKey = await be8.getDerivedKey(publicKey, privateKey);
const { cipherText, iv } = await be8.encryptText(derivedKey, text);
With the help of the key, the cipherText and an iv, we can decrypt messages.
const cipherText = 'ASDASD9324/&§$jn';
const iv = '213210931249713409';
const derivedKey = await be8.getDerivedKey(publicKey, privateKey);
const text = await be8.decryptText(derivedKey, cipherText);
encryptTextSimple is a compound function of encryptText and getDerivedKey. It uses the ids instead of keys. The derivedKey is generated inside the function.
const accIDSender = '101010';
const accIDReceiver = '101011';
const text = 'Hello World';
const cipherText = await be8.encryptTextSimple(accIDSender, accIDReceiver, text);
decryptTextSimple is a compound function of decryptText and getDerivedKey. It uses the ids instead of keys. The derivedKey is generated inside the function.
const accIDSender = '101010';
const accIDReceiver = '101011';
const cipherText = 'sadadwWE=)AWLKASDS';
const iv = '2139484765456789';
const cipherText = await be8.decryptTextSimple(accIDSender, accIDReceiver, cipherText, iv);
Accepts the derivedKey and an image encoded as base64 so it can creates a "cipherImage" and an iv.
const { cipherImage, iv } = await be8.encryptImage(derivedKey, base64Image);
Uses the derivedKey, the cipherImage and the iv to decrypt a base64Image.
const base64Image = await be8.encryptImage(derivedKey, cipherImage, iv);
const base64Image = await be8.encryptImageSimple(accIDSender, accIDReceiver, base64Image);
const base64Image = await be8.decryptImageSimple(accIDSender, accIDReceiver, cipherImage, iv);
Rollup creates two versions one is a esm6 version and a minified iife one. Both can be found in /dist.
npm run build
Open http://localhost:3000/ in your browser to see the qunit suite.
npm test