Skip to content

Basic security API for Typescript that optimizes for easy use

License

Notifications You must be signed in to change notification settings

bradclawsie/easysecurity

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

easysecurity

Basic security API for Typescript that optimizes for easy use

License:MIT ci

Important Compatibility Note

Note that there will be breaking changes introduced after version 0.1.9. These changes will start a 0.2.x version scheme. If you have a dependency on this library as it is presently developed, I recommend fixing your use at version 0.1.9 until you can undertake a migration forward. Alternately, you may wish to simply fork version 0.1.9.

Motivation

I find most security APIs hard to use. What I'm usually looking for is simple ways to hash values, encrypt/decrypt values, and generate random strings.

In almost all cases, I want to work with values that can be printed and stored directly, which for me means using hex encoding as a serialization format.

This module is not for cryptography experts. This module is not for people who want to tune parameters. This module is for people for whom AES-CBC is a "good enough" cipher, for whom v4 UUIDs are a "good enough" random value, and for whom sha256 is a "good enough" hash.

Check out test.ts for some good copy-paste code samples.

Import

import * as easysecurity from "https://deno.land/x/easysecurity/mod.ts";

Hashing

sha256Hex(input); // sha256 input and hex-encode

Random Values

randomUUID(); // re-export crypto.randomUUID();

Encryption/Decryption

// generate a Crypter using new, random key and IV
// (you can access them via crypter.Key, crypter.IV)
const crypter = Crypter.generate();

// or maybe you already have hex-exported Key and IV that you had stored
const crypter = Crypter.fromHex(hexKey, hexIV);

// or maybe you want to generate new Key and IV
const key = await Key.generate();
const iv = IV.fromString("user@example.com");
const crypter = await new Crypter(key, iv);

// or you want to create Key and IV instances directly from
// hex - exports;
const key = await Key.fromHex(hexKey);
const iv = IV.fromHex(hexIV);

// and you can make these exports easily:
const hexKey = key.toHex();
const hexIV = iv.toHex();

// to encrypt some clear text:
const clearText = "hello world";
const hexCrypted = await crypter.encryptToHex(clearText);

// ...and get the clear text back
const decrypted = await crypter.decryptFromHex(hexCrypted);

About

Basic security API for Typescript that optimizes for easy use

Resources

License

Stars

Watchers

Forks

Packages

No packages published