Skip to content

Commit

Permalink
Fixed typo from encription to encryption
Browse files Browse the repository at this point in the history
  • Loading branch information
jormaechea committed Feb 4, 2021
1 parent 3866217 commit 466645c
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 42 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -19,7 +19,7 @@ There are 5 groups of functionalities in this module. You can require each one o
```js
const {
Base64,
Encription,
Encryption,
Hash,
Random,
UUID
Expand Down
36 changes: 18 additions & 18 deletions docs/Encription.md → docs/Encryption.md
Expand Up @@ -2,51 +2,51 @@
Run `npm run docs` to regenerate it. -->

<a name="module_Encription"></a>
<a name="module_Encryption"></a>

## Encription
Handles string encription and decription
## Encryption
Handles string encryption and decription


* [Encription](#module_Encription)
* [.algorithms](#module_Encription.algorithms)
* [.unsafeEncrypt(plainTextString, [algorithm])](#module_Encription.unsafeEncrypt) ⇒ <code>Promise.&lt;string&gt;</code>
* [.unsafeDecrypt(encryptedString, [algorithm])](#module_Encription.unsafeDecrypt) ⇒ <code>Promise.&lt;string&gt;</code>
* [Encryption](#module_Encryption)
* [.algorithms](#module_Encryption.algorithms)
* [.unsafeEncrypt(plainTextString, [algorithm])](#module_Encryption.unsafeEncrypt) ⇒ <code>Promise.&lt;string&gt;</code>
* [.unsafeDecrypt(encryptedString, [algorithm])](#module_Encryption.unsafeDecrypt) ⇒ <code>Promise.&lt;string&gt;</code>

<a name="module_Encription.algorithms"></a>
<a name="module_Encryption.algorithms"></a>

### Encription.algorithms
### Encryption.algorithms
A key-value of the available algorithms: `AES128`, `AES192` and `AES256`.

**Kind**: static property of [<code>Encription</code>](#module_Encription)
**Kind**: static property of [<code>Encryption</code>](#module_Encryption)
**Read only**: true
**Example**
```js
doSomething(Encription.algorithms.AES128);
doSomething(Encryption.algorithms.AES128);
```
<a name="module_Encription.unsafeEncrypt"></a>
<a name="module_Encryption.unsafeEncrypt"></a>

### Encription.unsafeEncrypt(plainTextString, [algorithm]) ⇒ <code>Promise.&lt;string&gt;</code>
Encrypts a string using an encription algorithm and returns it in hex string format.
### Encryption.unsafeEncrypt(plainTextString, [algorithm]) ⇒ <code>Promise.&lt;string&gt;</code>
Encrypts a string using an encryption algorithm and returns it in hex string format.

**IMPORTANT**: This method is not cryptographically secure. It uses a fixed non-random salt and initialization vector.

**Kind**: static method of [<code>Encription</code>](#module_Encription)
**Kind**: static method of [<code>Encryption</code>](#module_Encryption)
**Returns**: <code>Promise.&lt;string&gt;</code> - Encrypted string in hex format

| Param | Type | Default | Description |
| --- | --- | --- | --- |
| plainTextString | <code>string</code> | | String to encrypt |
| [algorithm] | <code>algorithms</code> | <code>this.algorithms.AES128</code> | Algorithm to use for encrypt the string |

<a name="module_Encription.unsafeDecrypt"></a>
<a name="module_Encryption.unsafeDecrypt"></a>

### Encription.unsafeDecrypt(encryptedString, [algorithm]) ⇒ <code>Promise.&lt;string&gt;</code>
### Encryption.unsafeDecrypt(encryptedString, [algorithm]) ⇒ <code>Promise.&lt;string&gt;</code>
Decrypts a previously encrypted string with the specified algorithm

**IMPORTANT**: This method is not cryptographically secure. It uses a fixed non-random salt and initialization vector

**Kind**: static method of [<code>Encription</code>](#module_Encription)
**Kind**: static method of [<code>Encryption</code>](#module_Encryption)
**Returns**: <code>Promise.&lt;string&gt;</code> - Decrypted hex string

| Param | Type | Default | Description |
Expand Down
2 changes: 1 addition & 1 deletion docs/README.md
Expand Up @@ -5,7 +5,7 @@ Run `npm run docs` to regenerate it. -->
See documentation for each module:

- [Base64](Base64.md)
- [Encription](Encription.md)
- [Encryption](Encryption.md)
- [Hash](Hash.md)
- [Random](Random.md)
- [UUID](UUID.md)
File renamed without changes.
12 changes: 6 additions & 6 deletions lib/encription.js → lib/encryption.js
Expand Up @@ -3,31 +3,31 @@
const crypto = require('crypto');
const { promisify } = require('util');

const { algorithms, getAlgorithmAttributes } = require('./encription-algorithms');
const { algorithms, getAlgorithmAttributes } = require('./encryption-algorithms');

const scryptAsync = promisify(crypto.scrypt);

const unsafeSalt = Buffer.alloc(16, 0);
const initVector = Buffer.alloc(16, 0);

/**
* @module Encription
* @description Handles string encription and decription
* @module Encryption
* @description Handles string encryption and decription
*/
module.exports = class Encription {
module.exports = class Encryption {

/**
* A key-value of the available algorithms: `AES128`, `AES192` and `AES256`.
*
* @readonly
* @example doSomething(Encription.algorithms.AES128);
* @example doSomething(Encryption.algorithms.AES128);
*/
static get algorithms() {
return algorithms;
}

/**
* Encrypts a string using an encription algorithm and returns it in hex string format.
* Encrypts a string using an encryption algorithm and returns it in hex string format.
*
* **IMPORTANT**: This method is not cryptographically secure. It uses a fixed non-random salt and initialization vector.
*
Expand Down
4 changes: 2 additions & 2 deletions lib/index.js
Expand Up @@ -2,14 +2,14 @@

const Base64 = require('./base64');
const Hash = require('./hash');
const Encription = require('./encription');
const Encryption = require('./encryption');
const Random = require('./random');
const UUID = require('./uuid');

module.exports = {
Base64,
Hash,
Encription,
Encryption,
Random,
UUID
};
28 changes: 14 additions & 14 deletions tests/encription.js → tests/encryption.js
Expand Up @@ -2,9 +2,9 @@

const assert = require('assert');

const { Encription } = require('../lib');
const { Encryption } = require('../lib');

describe('Encription', () => {
describe('Encryption', () => {

const plainTextString = 'Hi there, I am a test';
const encodedStringWithAES128 = '26ffc79ef45a8d6ff461cf3fa6ff8b67b7545347d3b5d18d904a2c85d4ec08f5';
Expand All @@ -13,30 +13,30 @@ describe('Encription', () => {

describe('algorithms getter', () => {

it('Should return an object with the encription algorithms enum', () => {
assert(Encription.algorithms);
assert.strictEqual(typeof Encription.algorithms, 'object');
assert.strictEqual(Encription.algorithms.AES128, 'AES128');
assert.strictEqual(Encription.algorithms.AES192, 'AES192');
assert.strictEqual(Encription.algorithms.AES256, 'AES256');
it('Should return an object with the encryption algorithms enum', () => {
assert(Encryption.algorithms);
assert.strictEqual(typeof Encryption.algorithms, 'object');
assert.strictEqual(Encryption.algorithms.AES128, 'AES128');
assert.strictEqual(Encryption.algorithms.AES192, 'AES192');
assert.strictEqual(Encryption.algorithms.AES256, 'AES256');
});

});

describe('unsafeEncrypt()', () => {

it('Should resolve the encripted string using AES128 by default', async () => {
const encriptedString = await Encription.unsafeEncrypt(plainTextString);
const encriptedString = await Encryption.unsafeEncrypt(plainTextString);
assert.strictEqual(encriptedString, encodedStringWithAES128);
});

it('Should resolve the encripted string using a AES192 algorithm if passed as param', async () => {
const encriptedString = await Encription.unsafeEncrypt(plainTextString, Encription.algorithms.AES192);
const encriptedString = await Encryption.unsafeEncrypt(plainTextString, Encryption.algorithms.AES192);
assert.strictEqual(encriptedString, encodedStringWithAES192);
});

it('Should resolve the encripted string using a AES256 algorithm if passed as param', async () => {
const encriptedString = await Encription.unsafeEncrypt(plainTextString, Encription.algorithms.AES256);
const encriptedString = await Encryption.unsafeEncrypt(plainTextString, Encryption.algorithms.AES256);
assert.strictEqual(encriptedString, encodedStringWithAES256);
});

Expand All @@ -45,17 +45,17 @@ describe('Encription', () => {
describe('unsafeDecrypt()', () => {

it('Should resolve the plain text string using AES128 by default', async () => {
const decriptedString = await Encription.unsafeDecrypt(encodedStringWithAES128);
const decriptedString = await Encryption.unsafeDecrypt(encodedStringWithAES128);
assert.strictEqual(decriptedString, plainTextString);
});

it('Should resolve the plain text string using a AES192 algorithm if passed as param', async () => {
const decriptedString = await Encription.unsafeDecrypt(encodedStringWithAES192, Encription.algorithms.AES192);
const decriptedString = await Encryption.unsafeDecrypt(encodedStringWithAES192, Encryption.algorithms.AES192);
assert.strictEqual(decriptedString, plainTextString);
});

it('Should resolve the plain text string using a AES256 algorithm if passed as param', async () => {
const decriptedString = await Encription.unsafeDecrypt(encodedStringWithAES256, Encription.algorithms.AES256);
const decriptedString = await Encryption.unsafeDecrypt(encodedStringWithAES256, Encryption.algorithms.AES256);
assert.strictEqual(decriptedString, plainTextString);
});

Expand Down

0 comments on commit 466645c

Please sign in to comment.