endecoder
TypeScript icon, indicating that this package has built-in type declarations

1.5.2 • Public • Published

endecoder

A module can encode/decode strings with the keys.
See endecoder-npm.netlify.app for details.

npm NPM npms.io (quality) Libraries.io dependency status for latest release Maintenance

Installation

npm install endecoder

Usage

encode / decode easily

import { encode, decode } from "endecoder";

const PLAIN_TEXT = "this is a test string !#$%&'()";

const { data: encoded, options } = encode(PLAIN_TEXT);
// save options for decoding

const decoded = decode(encoded, options);

console.log(PLAIN_TEXT == decoded);
// true

more detailed

import { SecretKey } from "endecoder";

const PLAIN_TEXT = "this is a test string !#$%&'()";

const password = "testpassword!!#$%";
const salt = "salt///:*";

const key = SecretKey.activate({
  password,
  salt
});

const encoded = key.encode(PLAIN_TEXT);
console.log(encoded);

console.log(key.decode(encoded) == PLAIN_TEXT);
// true

// wrong password and salt combination
const alt_key = SecretKey.activate({
  password,
  salt: "salt///;*"
});

try{
  const decoded = alt_key.decode(encoded);
  console.log(decoded == PLAIN_TEXT);
  // will be false
}catch(error){
  // or an error may occur
}

SecretKey class

interface SecretKeyOptions {
    algorithm?: string;
    password?: string;
    salt?: string;
}

class SecretKey {
  constructor(options?: SecretKeyOptions);
  public encode(data: string): string;
  public decode(data: string): string;
  public encrypt(data: Buffer): Promise<string>;
  public decrypt(data: string): Promise<Buffer>;
  public static activate(options?: SecretKeyOptions): SecretKey;
  public static generateKeys(): {
    algorithm: string;
    password: string;
    salt: string;
  };
}

Package Sidebar

Install

npm i endecoder

Weekly Downloads

2

Version

1.5.2

License

MIT

Unpacked Size

19.8 kB

Total Files

5

Last publish

Collaborators

  • tomsd