New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

endecoder

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

endecoder

A module can encode/decode strings with the keys.

latest
Source
npmnpm
Version
1.5.2
Version published
Maintainers
1
Created
Source

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;
  };
}

Keywords

encryption

FAQs

Package last updated on 02 Jan 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts