Simple Encryption Library for encrypting strings and integers into unique tokens, safe for use in URL paths and queries. Supports 64bit signed and unsigned big endians.
// Via NPM
$ npm install --save encrypt-decrypt-library
// Via Yarn
$ yarn add encrypt-decrypt-library
import Encryption from "encrypt-decrypt-library";
const config = {
algorithm: process.env.ALGORITHM,
encryptionKey: process.env.ENCRYPTION_KEY,
salt: process.env.SALT,
}
const encryption = new Encryption(config);
encryption.encrypt('Hello world')
// xxxxxxx
The library requires the following configuration options:
-
algorithm:
String
- The algorithm type to be used by the library -
encryptionKey:
String
- The encryption key to be used by the library -
salt:
String
- The salt to be used by the library
Returns an encrypted value.
Type: string
-
The value that will be encrypted.
Type: boolean
(optional) -
The type of value. Provides support for Big Integer encryption.
import Encryption from "encrypt-decrypt-library";
const config = {
algorithm: process.env.ALGORITHM,
encryptionKey: process.env.ENCRYPTION_KEY,
salt: process.env.SALT,
}
const encryption = new Encryption(config);
// Encrypted as a string
encryption.encrypt('Hello world')
// Encrypted as a string
encryption.encrypt('1234567890')
// Encrypted as an unsigned 64-bit Integer
encryption.encrypt(123, true)
Returns a decrypted value.
Type: string
-
The token that will be decrypted.
Type: boolean
(optional) -
The type of encrypted value if known. Provides support for decrypting small and big integers.
import Encryption from "encrypt-decrypt-library";
const config = {
algorithm: process.env.ALGORITHM,
encryptionKey: process.env.ENCRYPTION_KEY,
salt: process.env.SALT,
}
const encryption = new Encryption(config);
// Encoded as string
encryption.decrypt('gmmBh17Q4QA=')
// xxx
// Encoded as an integer
encryption.decrypt('NF1r855MimY=', true)
// xxx
Release management is automated using semantic-release.