Socket
Socket
Sign inDemoInstall

@element-ts/krypton

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@element-ts/krypton

A simple crypto library that wraps node and bcrypt.


Version published
Maintainers
1
Created
Source

krypton

A very light weight package written in Typescript combining node/crypto and bcrypt for some helpful methods.

NOTE, I am not using my own crypto with this project, it is using recommend crypto from node and bcrypt.

Import

Import what you need. You will most likely not need to import all of these.

import {
    KrBcrypt,
    KrHash,
    KrHashAlgorithm,
    KrRSA,
    KrRSAKeyPair
} from "element-ts/krypton";

Examples

KrBcrypt

const password: string = "1234";
const createdPassword: Buffer = await KrBcrypt.createPassword(password);
const checkPassword: boolean = await KrBcrypt.verifyPassword(password, createdPassword);

KrHash

const hashedData: Buffer = KrHash.hash(Buffer.from("Hello, world!");
const hashedData: Buffer = KrHash.hash(Buffer.from("Hello, world!", KrHashAlgorithm.sha512));

const hasher: KrHash = new KrHash()
hasher.append(Buffer.from("Hello"));
hasher.append(Buffer.from("World"));
const hashedData: Buffer = hasher.hash();

KrCipher

// instance
const cipher: KrCipher = new KrCipher(Buffer.from("password"));
const msg: Buffer = Buffer.from("Hello, world!");
const encryptedData: Buffer = cipher.encrypt(msg);
const decryptedData: Buffer = cipher.decrypt(encryptedData);
console.log(msg === decryptedData);

// static
const encryptedData: Buffer = KrCipher.encrypt(Buffer.from("Hello, world!"), Buffer.from("password"), Buffer.from("the-salt"));
const decryptedData: Buffer = KrCipher.decrypt(encryptedData, Buffer.from("password"), Buffer.from("the-salt"));

KrRSA


const keys: KrRSAKeyPair = KrRSA.generateKeys();

const message: string = "Hello, world!";
const dataUnEncrypted: Buffer = Buffer.from(message);
const dataEncrypted: Buffer = KrRSA.encrypt(dataUnEncrypted, keys.publicKey);
const dataDecrypted: Buffer = KrRSA.decrypt(dataEncrypted, keys.privateKey);

const messageDecrypted: string = dataDecrypted.toString("utf8");

Documentation

You can view the declaration files or even the source code on GitHub.

Bugs

If you find any bugs please create an issue on GitHub or if you are old fashioned email me at elijah@elijahcobb.com.

Keywords

FAQs

Package last updated on 23 Feb 2020

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc