A module that provides RSA & AES encryption interfaces
npm install e2ee-ts

- [x] Easy interfaces to safely encrypt / decrypt.
- [x] RSA & AES encryption algorithms.
- [x] PEM format export.
* Why should I use this?
* Installation
* APIs
* RSA-OAEP
* init()
* exportPublicKey()
* importClientPublic()
* encrypt()
* decrypt()
* spkiToPEM()
* AES-GCM
* init()
* exportKey()
* importBufferKey()
* encrypt()
* decrypt()
* Tests
yarn add e2ee-ts
`npm
`
npm i e2ee-ts
`RSA Client
$3
Creates a RSA key pair, note that the private key cannot be exported. This method must be called first before other methods can be called, otherwise, it will reject all the operations.
`js
const client = new RSAClient();
await client.init();
`$3
Exports the public key as ArrayBuffer. Returns Promise.
`js
const client = new RSAClient();
await client.init();
const expotedKey = await client.exportPublicKey();
`$3
Imports a public key into the object, which will be used for encryption.
`js
const client = new RSAClient();
await client.init();
const expotedKey = await client.exportPublicKey();const client2 = new RSAClient();
await client2.importClientPublic(expotedKey);
`$3
Encrypts BufferSource using the public key. Returns Promise.
`js
await client.encrypt(
message as ArrayBuffer,
);
`$3
Decrypts ArrayBuffer using the private key. Returns Promise.
`js
await client.decrypt(
encryptedMessage as ArrayBuffer
);
`$3
Converts spki into human readable PEM format.
`js
const client = new RSAClient();
await client.init();
const expotedKey = await client.exportPublicKey();
const pem = client.spkiToPEM(expotedKey)`AES Client
$3
Generates a AES key, note that the private key cannot be exported. This method must be called first before other methods can be called, otherwise, it will reject all the operations.
`js
const client = new AESClient();
await client.init();
`$3
Exports the key as ArrayBuffer. Returns Promise.
`js
const client = new AESClient();
await client.init();
const expotedKey = await client.exportKey();
`$3
Imports a key into the object, which will be used for encryption.
`js
const client = new AESClient();
await client.init();
const expotedKey = await client.exportKey();const client2 = new AESClient();
await client2.importBufferKey(expotedKey);
`$3
Encrypts BufferSource using the public key. Returns Promise.
`js
await client.encrypt(
message as ArrayBuffer,
);
`$3
Decrypts ArrayBuffer using the private key. Returns Promise.
`js
await client.decrypt(
encryptedMessage as ArrayBuffer
);
`
Tests
All unit test cases are defined under \_\_tests\_\_ folder.
Run it with:
`
npm run test
``