npm.io
1.0.0 • Published 7 years ago

@flk/crypto

Licence
—
Version
1.0.0
Deps
1
Size
4 kB
Vulns
2
Weekly
0

Crypto

A simple Encryption/Decryption handler.

The current followed encryption algorithm is AES.

Installation

flk install flk-crypto

OR

npm install flk-crypto

Alias: crypto.

Table of contents

Usage

  let crypto = DI.resolve('crypto');

  let encryptedValue = crypto.encrypt('hello world');

Available methods

encrypt

encrypt(value: any): String Encrypt the given value.

This method accepts any type of values, it will be handled automatically, that means you can encrypt scalar values (string|boolean|number), arrays or objects.

Examples

  let crypto = DI.resolve('crypto');

  let encryptedValue = crypto.encrypt('hello world');

  // encrypt objects
  let user = {
    name: 'Hasan',
    age: 30,
  };

  let encryptedObject = crypto.encrypt(user);

Decrypt

decrypt(encodedValue: String): any|null Decrypt the given encoded value.

Examples
let user = crypto.decrypt('some-encoded-value');

Configurations

Available configurations for crypto in Application configurations.

Main Configuration key: crypto

key Type Description
key String Set the encryption/decryption key, by default it is the current application name.

Keywords